simpleCallableNodeTraverser = $simpleCallableNodeTraverser; $this->nodeNameResolver = $nodeNameResolver; $this->nodeTypeResolver = $nodeTypeResolver; } public function containsMockAsUsedVariable(ClassMethod $classMethod) : bool { $doesContainMock = \false; $this->simpleCallableNodeTraverser->traverseNodesWithCallable($classMethod, function (Node $node) use(&$doesContainMock) { if ($this->isMockeryStaticCall($node)) { $doesContainMock = \true; return null; } if (!$node instanceof PropertyFetch && !$node instanceof Variable) { return null; } $variableType = $this->nodeTypeResolver->getType($node); if ($variableType instanceof MixedType) { return null; } if ($this->isIntersectionTypeWithMockObject($variableType)) { $doesContainMock = \true; } if ($variableType->isSuperTypeOf(new ObjectType('PHPUnit\\Framework\\MockObject\\MockObject'))->yes()) { $doesContainMock = \true; } return null; }); return $doesContainMock; } private function isIntersectionTypeWithMockObject(Type $variableType) : bool { if ($variableType instanceof IntersectionType) { foreach ($variableType->getTypes() as $variableTypeType) { if ($variableTypeType->isSuperTypeOf(new ObjectType('PHPUnit\\Framework\\MockObject\\MockObject'))->yes()) { return \true; } } } return \false; } private function isMockeryStaticCall(Node $node) : bool { if (!$node instanceof StaticCall) { return \false; } // is mockery mock if (!$this->nodeNameResolver->isName($node->class, 'Mockery')) { return \false; } return $this->nodeNameResolver->isName($node->name, 'mock'); } }