staticGuard = $staticGuard; } public function getRuleDefinition() : RuleDefinition { return new RuleDefinition('Changes Closure to be static when possible', [new CodeSample(<<<'CODE_SAMPLE' function () { if (rand(0, 1)) { return 1; } return 2; } CODE_SAMPLE , <<<'CODE_SAMPLE' static function () { if (rand(0, 1)) { return 1; } return 2; } CODE_SAMPLE )]); } /** * @return array> */ public function getNodeTypes() : array { return [Closure::class]; } /** * @param Closure $node */ public function refactor(Node $node) : ?Node { if (!$this->staticGuard->isLegal($node)) { return null; } $node->static = \true; return $node; } }