-
-
Notifications
You must be signed in to change notification settings - Fork 337
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
RemoveUnusedNonEmptyArrayBeforeForeachRector: skip array dim fetch (#…
…5166) * RemoveUnusedNonEmptyArrayBeforeForeachRector: skip array dim fetch * fix with known offset * test phpdoc array shape * refactor * simplify test
- Loading branch information
Showing
4 changed files
with
134 additions
and
10 deletions.
There are no files selected for viewing
59 changes: 59 additions & 0 deletions
59
.../If_/RemoveUnusedNonEmptyArrayBeforeForeachRector/Fixture/offset_exists_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,59 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\DeadCode\Rector\If_\RemoveUnusedNonEmptyArrayBeforeForeachRector\Fixture; | ||
|
||
class KnownOffset | ||
{ | ||
public const DEFAULT_GROUP = 'default'; | ||
|
||
/** | ||
* @var array<string, list<self>> | ||
*/ | ||
private static $groups = []; | ||
|
||
public static function knownOffset(): array | ||
{ | ||
$group = 'default'; | ||
|
||
self::$groups[$group] = ["foo"]; | ||
|
||
if (! empty(self::$groups[$group])) { | ||
foreach (self::$groups[$group] as $group) { | ||
echo "hello"; | ||
} | ||
} | ||
|
||
return []; | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\DeadCode\Rector\If_\RemoveUnusedNonEmptyArrayBeforeForeachRector\Fixture; | ||
|
||
class KnownOffset | ||
{ | ||
public const DEFAULT_GROUP = 'default'; | ||
|
||
/** | ||
* @var array<string, list<self>> | ||
*/ | ||
private static $groups = []; | ||
|
||
public static function knownOffset(): array | ||
{ | ||
$group = 'default'; | ||
|
||
self::$groups[$group] = ["foo"]; | ||
|
||
foreach (self::$groups[$group] as $group) { | ||
echo "hello"; | ||
} | ||
|
||
return []; | ||
} | ||
} | ||
|
||
?> |
24 changes: 24 additions & 0 deletions
24
...RemoveUnusedNonEmptyArrayBeforeForeachRector/Fixture/skip_phpdoc_offset_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,24 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\DeadCode\Rector\If_\RemoveUnusedNonEmptyArrayBeforeForeachRector\Fixture; | ||
|
||
class SkipPhpdocOffset | ||
{ | ||
/** | ||
* @param array{default: foo} $array | ||
*/ | ||
public static function knownOffset($array): array | ||
{ | ||
$group = 'default'; | ||
|
||
if (! empty($array[$group])) { | ||
foreach ($array[$group] as $groupValue) { | ||
echo "hello"; | ||
} | ||
} | ||
|
||
return []; | ||
} | ||
} | ||
|
||
?> |
24 changes: 24 additions & 0 deletions
24
.../If_/RemoveUnusedNonEmptyArrayBeforeForeachRector/Fixture/skip_property_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,24 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\DeadCode\Rector\If_\RemoveUnusedNonEmptyArrayBeforeForeachRector\Fixture; | ||
|
||
class SkipPropertyDimFetch | ||
{ | ||
public const DEFAULT_GROUP = 'default'; | ||
|
||
/** | ||
* @var array<string, list<self>> | ||
*/ | ||
private static $groups = []; | ||
|
||
public static function getFootnotes($group = self::DEFAULT_GROUP): array | ||
{ | ||
if (! empty(self::$groups[$group])) { | ||
foreach (self::$groups[$group] as $note) { | ||
echo "hello"; | ||
} | ||
} | ||
|
||
return []; | ||
} | ||
} |
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