binaryOpManipulator = $binaryOpManipulator; } /** * getRuleDefinition * * @return RuleDefinition * @throws PoorDocumentationException */ public function getRuleDefinition(): RuleDefinition { return new RuleDefinition( 'Change exit(-x) int exit(x)', [new CodeSample( 'exit(-2)', 'exit(2)' )] ); } /** * Return a node type from https://github.com/rectorphp/php-parser-nodes-docs/ * * @return string[] */ public function getNodeTypes(): array { return [FuncCall::class]; } /** * refactor * * @param Node $node A node * @return FuncCall|BooleanNot */ public function refactor(Node $node) { if ($node instanceof FuncCall) { $tmpfunctionname = $this->getName($node); // If function is ok. We must avoid a lot of cases like isset(), empty() if (in_array($tmpfunctionname, array('exit'))) { //print "tmpfunctionname=".$tmpfunctionname."\n"; $args = $node->getArgs(); $nbofparam = count($args); if ($nbofparam >= 1) { $tmpargs = $args; foreach ($args as $key => $arg) { // only 1 element in this array //var_dump($key); //var_dump($arg->value);exit; if (empty($arg->value)) { return; } $a = new FuncCall(new Name('exit'), [new Arg(abs($arg->value))]); //$tmpargs[$key] = new Arg($a); return $a; //$r = new FuncCall(new Name($tmpfunctionname), $tmpargs); //return $r; } } } return $node; } return null; } }