-
-
Notifications
You must be signed in to change notification settings - Fork 336
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix var/property usage for RemoveUnusedNonEmptyArrayBeforeForeachRect…
…or. (#3040)
- Loading branch information
Showing
4 changed files
with
83 additions
and
12 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
...DeadCode/Rector/If_/RemoveUnusedNonEmptyArrayBeforeForeachRector/Fixture/if_check.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,35 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\DeadCode\Rector\If_\RemoveUnusedNonEmptyArrayBeforeForeachRector\Fixture; | ||
|
||
class IfCheck | ||
{ | ||
public function run() | ||
{ | ||
$values = []; | ||
if ($values) { | ||
foreach ($values as $value) { | ||
echo $value; | ||
} | ||
} | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\DeadCode\Rector\If_\RemoveUnusedNonEmptyArrayBeforeForeachRector\Fixture; | ||
|
||
class IfCheck | ||
{ | ||
public function run() | ||
{ | ||
$values = []; | ||
foreach ($values as $value) { | ||
echo $value; | ||
} | ||
} | ||
} | ||
|
||
?> |
22 changes: 22 additions & 0 deletions
22
...r/If_/RemoveUnusedNonEmptyArrayBeforeForeachRector/Fixture/skip_if_class_property.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,22 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\DeadCode\Rector\If_\RemoveUnusedNonEmptyArrayBeforeForeachRector\Fixture; | ||
|
||
class SkipIfClassProperty | ||
{ | ||
/** @var string[] */ | ||
private array $allowedValues = []; | ||
|
||
protected function filterValues(array $values): array | ||
{ | ||
if ($this->allowedValues) { | ||
foreach ($values as $index => $value) { | ||
if (!isset($this->allowedValues[$value])) { | ||
unset($values[$index]); | ||
} | ||
} | ||
} | ||
|
||
return $values; | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
...ctor/If_/RemoveUnusedNonEmptyArrayBeforeForeachRector/Fixture/skip_value_can_null.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,17 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\DeadCode\Rector\If_\RemoveUnusedNonEmptyArrayBeforeForeachRector\Fixture; | ||
|
||
class SkipPropertyNull | ||
{ | ||
private $items = null; | ||
|
||
public function run() | ||
{ | ||
if ($this->items) { | ||
foreach ($this->items as $value) { | ||
echo $value; | ||
} | ||
} | ||
} | ||
} |
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