-
-
Notifications
You must be signed in to change notification settings - Fork 335
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DeadCode] Handle edge cases on RemoveJustVariableAssignRector (#2621)
* [DeadCode] Handle edge cases on RemoveJustVariableAssignRector * indirect next used * skip with var doc * merge comment * handle indirect used * skip @var usage * merge comment * clean up * final touch: fixture for next used outside parent if
- Loading branch information
1 parent
3120994
commit dfc6e1d
Showing
7 changed files
with
107 additions
and
30 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
37 changes: 37 additions & 0 deletions
37
...e/Rector/StmtsAwareInterface/RemoveJustVariableAssignRector/Fixture/merge_comment.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,37 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\DeadCode\Rector\StmtsAwareInterface\RemoveJustVariableAssignRector\Fixture; | ||
|
||
final class SomeClass | ||
{ | ||
private int $temporaryValue; | ||
|
||
public function run() | ||
{ | ||
// some comment | ||
$result = execute(); | ||
|
||
// another comment | ||
$this->temporaryValue = $result; | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\DeadCode\Rector\StmtsAwareInterface\RemoveJustVariableAssignRector\Fixture; | ||
|
||
final class SomeClass | ||
{ | ||
private int $temporaryValue; | ||
|
||
public function run() | ||
{ | ||
// some comment | ||
// another comment | ||
$this->temporaryValue = execute(); | ||
} | ||
} | ||
|
||
?> |
21 changes: 21 additions & 0 deletions
21
...tmtsAwareInterface/RemoveJustVariableAssignRector/Fixture/skip_indirect_next_used.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,21 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\DeadCode\Rector\StmtsAwareInterface\RemoveJustVariableAssignRector\Fixture; | ||
|
||
final class SkipIndirectNextUsed | ||
{ | ||
public function run() | ||
{ | ||
$result = execute(); | ||
$this->temporaryValue = $result; | ||
|
||
otherCode(); | ||
otherCode(); | ||
|
||
function () use ($result) { | ||
|
||
}; | ||
|
||
echo $result; | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
...Interface/RemoveJustVariableAssignRector/Fixture/skip_indirect_next_used_after_if.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,16 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\DeadCode\Rector\StmtsAwareInterface\RemoveJustVariableAssignRector\Fixture; | ||
|
||
final class SkipIndirectNextUsedAfterIf | ||
{ | ||
public function run() | ||
{ | ||
if (rand(0, 1)) { | ||
$result = execute(); | ||
$this->temporaryValue = $result; | ||
} | ||
|
||
echo $result ?? 'test'; | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
...ctor/StmtsAwareInterface/RemoveJustVariableAssignRector/Fixture/skip_with_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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\DeadCode\Rector\StmtsAwareInterface\RemoveJustVariableAssignRector\Fixture; | ||
|
||
final class SkipWithVarDoc | ||
{ | ||
public function run() | ||
{ | ||
/** @var string $result */ | ||
$result = execute(); | ||
$this->temporaryValue = $result; | ||
} | ||
} |
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