silentVoidResolver = $silentVoidResolver; } public function getRuleDefinition() : RuleDefinition { return new RuleDefinition('Add closure return type void if there is no return', [new CodeSample(<<<'CODE_SAMPLE' function () { } CODE_SAMPLE , <<<'CODE_SAMPLE' function (): void { } CODE_SAMPLE )]); } /** * @return array> */ public function getNodeTypes() : array { return [Closure::class]; } /** * @param Closure $node */ public function refactor(Node $node) : ?Node { // already has return type → skip if ($node->returnType instanceof Node) { return null; } if (!$this->silentVoidResolver->hasExclusiveVoid($node)) { return null; } $node->returnType = new Identifier('void'); return $node; } public function provideMinPhpVersion() : int { return PhpVersionFeature::VOID_TYPE; } }