strictBoolReturnTypeAnalyzer = $strictBoolReturnTypeAnalyzer; $this->classMethodReturnTypeOverrideGuard = $classMethodReturnTypeOverrideGuard; } public function getRuleDefinition() : RuleDefinition { return new RuleDefinition('Add strict return type based on returned strict expr type', [new CodeSample(<<<'CODE_SAMPLE' final class SomeClass { public function run() { return $this->first() && $this->somethingElse(); } } CODE_SAMPLE , <<<'CODE_SAMPLE' final class SomeClass { public function run(): bool { return $this->first() && $this->somethingElse(); } } CODE_SAMPLE )]); } /** * @return array> */ public function getNodeTypes() : array { return [ClassMethod::class, Function_::class, Closure::class]; } /** * @param ClassMethod|Function_|Closure $node */ public function refactorWithScope(Node $node, Scope $scope) : ?Node { if ($node->returnType instanceof Node) { return null; } if ($node instanceof ClassMethod && $this->classMethodReturnTypeOverrideGuard->shouldSkipClassMethod($node, $scope)) { return null; } if (!$this->strictBoolReturnTypeAnalyzer->hasAlwaysStrictBoolReturn($node)) { return null; } $node->returnType = new Identifier('bool'); return $node; } public function provideMinPhpVersion() : int { return PhpVersion::PHP_70; } }