reflectionResolver = $reflectionResolver; } /** * @param MethodCall[] $chainMethodCalls */ public function haveSingleClass(array $chainMethodCalls) : bool { // are method calls located in the same class? $classOfClassMethod = []; foreach ($chainMethodCalls as $chainMethodCall) { $methodReflection = $this->reflectionResolver->resolveMethodReflectionFromMethodCall($chainMethodCall); if ($methodReflection instanceof \PHPStan\Reflection\MethodReflection) { $declaringClass = $methodReflection->getDeclaringClass(); $classOfClassMethod[] = $declaringClass->getName(); } else { $classOfClassMethod[] = null; } } $uniqueClasses = \array_unique($classOfClassMethod); return \count($uniqueClasses) < 2; } /** * @param string[] $calleeUniqueTypes */ public function isCorrectTypeCount(array $calleeUniqueTypes, \Rector\Defluent\Contract\ValueObject\FirstCallFactoryAwareInterface $firstCallFactoryAware) : bool { if ($calleeUniqueTypes === []) { return \false; } // in case of factory method, 2 methods are allowed if ($firstCallFactoryAware->isFirstCallFactory()) { return \count($calleeUniqueTypes) === 2; } return \count($calleeUniqueTypes) === 1; } }