argumentDefaultValueReplacer = $argumentDefaultValueReplacer;
}
public function getRuleDefinition() : RuleDefinition
{
return new RuleDefinition('Streamline the operator arguments of version_compare function', [new ConfiguredCodeSample(<<<'CODE_SAMPLE'
version_compare(PHP_VERSION, '5.6', 'gte');
CODE_SAMPLE
, <<<'CODE_SAMPLE'
version_compare(PHP_VERSION, '5.6', 'ge');
CODE_SAMPLE
, [new ReplaceFuncCallArgumentDefaultValue('version_compare', 2, 'gte', 'ge')])]);
}
/**
* @return array>
*/
public function getNodeTypes() : array
{
return [FuncCall::class];
}
/**
* @param FuncCall $node
*/
public function refactor(Node $node) : ?\PhpParser\Node\Expr\FuncCall
{
$hasChanged = \false;
foreach ($this->replacedArguments as $replacedArgument) {
if (!$this->isName($node->name, $replacedArgument->getFunction())) {
continue;
}
$changedNode = $this->argumentDefaultValueReplacer->processReplaces($node, $replacedArgument);
if ($changedNode instanceof Node) {
$hasChanged = \true;
}
}
if ($hasChanged) {
return $node;
}
return null;
}
/**
* @param mixed[] $configuration
*/
public function configure(array $configuration) : void
{
Assert::allIsAOf($configuration, ReplaceFuncCallArgumentDefaultValue::class);
$this->replacedArguments = $configuration;
}
}