-
-
Notifications
You must be signed in to change notification settings - Fork 372
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor SymplifyUselessVariableRector to avoid using PREVIOUS_NODE, …
…use current scope instead (#2045)
- Loading branch information
1 parent
b9a912b
commit a2ee46d
Showing
23 changed files
with
248 additions
and
274 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
.../CodeQuality/Rector/FunctionLike/SimplifyUselessVariableRector/Fixture/assign_ops.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\CodeQuality\Rector\FunctionLike\SimplifyUselessVariableRector\Fixture; | ||
|
||
function () { | ||
$b += 1; | ||
return $b; | ||
}; | ||
|
||
function () { | ||
$e /= 1; | ||
return $e; | ||
}; | ||
|
||
function () { | ||
$f **= 1; | ||
return $f; | ||
}; | ||
|
||
function () { | ||
$m .= 1; | ||
return $m; | ||
}; | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\CodeQuality\Rector\FunctionLike\SimplifyUselessVariableRector\Fixture; | ||
|
||
function () { | ||
return $b + 1; | ||
}; | ||
|
||
function () { | ||
return $e / 1; | ||
}; | ||
|
||
function () { | ||
return $f ** 1; | ||
}; | ||
|
||
function () { | ||
return $m . 1; | ||
}; | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
...sts/CodeQuality/Rector/FunctionLike/SimplifyUselessVariableRector/Fixture/fixture.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\CodeQuality\Rector\FunctionLike\SimplifyUselessVariableRector\Fixture; | ||
|
||
function () { | ||
$a = true; | ||
return $a; | ||
}; | ||
|
||
function sameVariableInDifferentScope() | ||
{ | ||
$n = array_map(function () { | ||
return $n + 1; | ||
}, []); | ||
|
||
return $n; | ||
} | ||
|
||
function moreVariableOneWithoutAssigment() { | ||
$o++; | ||
$o = 10; | ||
|
||
return $o; | ||
} | ||
|
||
function assigmentAsFunctionParametr() { | ||
doSomething($p = 0); | ||
return $p; | ||
} | ||
|
||
function assigmentAfterAssignment() { | ||
doSomething($qq = $q = 0); | ||
return $q; | ||
} | ||
|
||
function () { | ||
$a = 1; | ||
$b = 1; | ||
$c = [ | ||
$b-- => $a++, | ||
--$b => ++$a, | ||
]; | ||
return $c; | ||
}; | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\CodeQuality\Rector\FunctionLike\SimplifyUselessVariableRector\Fixture; | ||
|
||
function () { | ||
return true; | ||
}; | ||
|
||
function sameVariableInDifferentScope() | ||
{ | ||
return array_map(function () { | ||
return $n + 1; | ||
}, []); | ||
} | ||
|
||
function moreVariableOneWithoutAssigment() { | ||
$o++; | ||
|
||
return 10; | ||
} | ||
|
||
function assigmentAsFunctionParametr() { | ||
doSomething($p = 0); | ||
return $p; | ||
} | ||
|
||
function assigmentAfterAssignment() { | ||
doSomething($qq = $q = 0); | ||
return $q; | ||
} | ||
|
||
function () { | ||
$a = 1; | ||
$b = 1; | ||
return [ | ||
$b-- => $a++, | ||
--$b => ++$a, | ||
]; | ||
}; | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...riableRector/Fixture/keep_var_doc.php.inc → ...riableRector/Fixture/keep_var_doc.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ariableRector/Fixture/keep_visual.php.inc → ...ariableRector/Fixture/keep_visual.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...iableRector/Fixture/skip_fixture2.php.inc → ...iableRector/Fixture/skip_fixture2.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ctor/Fixture/skip_global_variable.php.inc → ...ctor/Fixture/skip_global_variable.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...Rector/Fixture/skip_return_by_ref.php.inc → ...Rector/Fixture/skip_return_by_ref.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ctor/Fixture/skip_static_variable.php.inc → ...ctor/Fixture/skip_static_variable.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ble_used_with_date_time_immutable.php.inc → ...ble_used_with_date_time_immutable.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.