-
-
Notifications
You must be signed in to change notification settings - Fork 364
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DeadCode] Skip property fetch on cond as may be overridden on Remove…
…AlwaysTrueIfConditionRector (#5796) * [DeadCode] Skip property fetch overriden by next method call on RemoveAlwaysTrueIfConditionRector * [ci-review] Rector Rectify * clean up * skip property fetch * skip * skip also ArrayDimFetch * also ArrayDimfetch --------- Co-authored-by: GitHub Action <actions@github.com>
- Loading branch information
1 parent
e503792
commit 91ed251
Showing
3 changed files
with
82 additions
and
30 deletions.
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
...eadCode/Rector/If_/RemoveAlwaysTrueIfConditionRector/Fixture/skip_array_dim_fetch.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,51 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\DeadCode\Rector\If_\RemoveAlwaysTrueIfConditionRector\Fixture; | ||
|
||
$changes = []; | ||
foreach (toAdd() as $add) { | ||
$changes[$add['id']]['add'][] = 1; | ||
} | ||
foreach (toRem() as $del) { | ||
$changes[$del['id']]['del'][] = 2; | ||
} | ||
foreach ($changes as $changeSet) { | ||
if (isset($changeSet['del'])) { | ||
echo 1; | ||
} | ||
if (isset($changeSet['add'])) { | ||
echo 2; | ||
} | ||
} | ||
|
||
/** | ||
* @return array{array{id: int}}|array{} | ||
*/ | ||
function toAdd(): array | ||
{ | ||
if (rand(0,1)) { | ||
return []; | ||
} | ||
|
||
return [ | ||
0 => [ | ||
'id' => 1, | ||
], | ||
]; | ||
} | ||
|
||
/** | ||
* @return array{array{id: int}}|array{} | ||
*/ | ||
function toRem(): array | ||
{ | ||
if (rand(0,1)) { | ||
return []; | ||
} | ||
|
||
return [ | ||
0 => [ | ||
'id' => 1, | ||
] | ||
]; | ||
} |
26 changes: 26 additions & 0 deletions
26
...r/If_/RemoveAlwaysTrueIfConditionRector/Fixture/skip_override_by_next_method_call.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,26 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\DeadCode\Rector\If_\RemoveAlwaysTrueIfConditionRector\Fixture; | ||
|
||
class SkipPropertyFetchOverriddenByNextMethodCall | ||
{ | ||
private bool $executed; | ||
|
||
public function run(): void | ||
{ | ||
$this->executed = false; | ||
|
||
$this->execute(); | ||
|
||
if (!$this->executed) { | ||
echo 'not run'; | ||
} | ||
} | ||
|
||
protected function execute() | ||
{ | ||
if (rand(0, 1)) { | ||
$this->executed = true; | ||
} | ||
} | ||
} |
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