followedByCommaAnalyzer = $followedByCommaAnalyzer; } public function getRuleDefinition() : RuleDefinition { return new RuleDefinition('Remove trailing commas in unset', [new CodeSample(<<<'CODE_SAMPLE' unset( $x, $y, ); CODE_SAMPLE , <<<'CODE_SAMPLE' unset( $x, $y ); CODE_SAMPLE )]); } /** * @return array> */ public function getNodeTypes() : array { return [Unset_::class]; } /** * @param Unset_ $node */ public function refactor(Node $node) : ?Node { if ($node->vars !== []) { \end($node->vars); $lastArgumentPosition = \key($node->vars); \reset($node->vars); $last = $node->vars[$lastArgumentPosition]; if (!$this->followedByCommaAnalyzer->isFollowed($this->file, $last)) { return null; } // remove comma $last->setAttribute(AttributeKey::FUNC_ARGS_TRAILING_COMMA, \false); $node->setAttribute(AttributeKey::ORIGINAL_NODE, null); return $node; } return null; } }