Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace Rector\Tests\Arguments\Rector\FuncCall\FunctionArgumentDefaultValueReplacerRector\Fixture;

class SkipVersionCompare
{
public function run()
{
version_compare($a, $b, $c);
version_compare(1, 2);
version_compare(PHP_VERSION, '5.6', 'le');
}
}

?>
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@ class VersionCompare
{
public function run()
{
version_compare(1, 2);
version_compare(1, 2, '');
version_compare(PHP_VERSION, '5.6', 'lte');
version_compare(PHP_VERSION, '5.6', 'le');
}
}

Expand All @@ -23,10 +21,8 @@ class VersionCompare
{
public function run()
{
version_compare(1, 2);
version_compare(1, 2, '!=');
version_compare(PHP_VERSION, '5.6', 'le');
version_compare(PHP_VERSION, '5.6', 'le');
}
}

Expand Down
4 changes: 3 additions & 1 deletion rules/Arguments/ArgumentDefaultValueReplacer.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,17 @@ private function processArgs(
$replaceArgumentDefaultValue->getValueBefore()
) && $argValue === $replaceArgumentDefaultValue->getValueBefore()) {
$expr->args[$position] = $this->normalizeValueToArgument($replaceArgumentDefaultValue->getValueAfter());
return $expr;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only return an Expr if the expr is actually changed, so that the rule is not applied if no change is made

} elseif (is_array($replaceArgumentDefaultValue->getValueBefore())) {
$newArgs = $this->processArrayReplacement($expr->getArgs(), $replaceArgumentDefaultValue);

if (is_array($newArgs)) {
$expr->args = $newArgs;
return $expr;
}
}

return $expr;
return null;
}

private function normalizeValueToArgument(mixed $value): Arg
Expand Down