callTypesResolver = $callTypesResolver; $this->classMethodParamTypeCompleter = $classMethodParamTypeCompleter; $this->localMethodCallFinder = $localMethodCallFinder; } public function getRuleDefinition() : RuleDefinition { return new RuleDefinition('Change private method param type to strict type, based on passed strict types', [new CodeSample(<<<'CODE_SAMPLE' final class SomeClass { public function run(int $value) { $this->resolve($value); } private function resolve($value) { } } CODE_SAMPLE , <<<'CODE_SAMPLE' final class SomeClass { public function run(int $value) { $this->resolve($value); } private function resolve(int $value) { } } CODE_SAMPLE )]); } /** * @return array> */ public function getNodeTypes() : array { return [Class_::class]; } /** * @param Class_ $node */ public function refactor(Node $node) : ?Node { $hasChanged = \false; foreach ($node->getMethods() as $classMethod) { if ($classMethod->params === []) { continue; } if (!$this->isClassMethodPrivate($node, $classMethod)) { continue; } if ($classMethod->isPublic()) { continue; } $methodCalls = $this->localMethodCallFinder->match($node, $classMethod); $classMethodParameterTypes = $this->callTypesResolver->resolveStrictTypesFromCalls($methodCalls); $classMethod = $this->classMethodParamTypeCompleter->complete($classMethod, $classMethodParameterTypes, self::MAX_UNION_TYPES); if ($classMethod instanceof ClassMethod) { $hasChanged = \true; } } if ($hasChanged) { return $node; } return null; } private function isClassMethodPrivate(Class_ $class, ClassMethod $classMethod) : bool { if ($classMethod->isPrivate()) { return \true; } if ($classMethod->isFinal() && !$class->extends instanceof Name && $class->implements === []) { return \true; } return $class->isFinal() && !$class->extends instanceof Name && $class->implements === [] && $classMethod->isProtected(); } }