Skip to content

Commit

Permalink
Check whether the early return matches the configured target path (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
zoglo authored Mar 5, 2025
1 parent 46490ec commit 82e5323
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/Rector/ReplaceNestedArrayItemRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,21 @@ private function matchPaths(array $targetPath, array $parentPath, array|string $
// Early return because we are already at the end of the path
if (self::PATH_END === $childTraversalPath)
{
// Array length differs thus not a real match
if (count($targetPath) !== count($parentPath))
{
return [];
}

// Match against the target path
foreach ($targetPath as $index => $value)
{
if ('*' !== $value && $value !== $parentPath[$index])
{
return [];
}
}

return [$parentPath];
}

Expand Down
21 changes: 21 additions & 0 deletions tests/Rector/ReplaceNestedArrayItemRector/fixture/model.php.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

class Foo
{
public function bar()
{
$arrOptions['limit'] = 1;
}
}
?>
-----
<?php

class Foo
{
public function bar()
{
$arrOptions['limit'] = 1;
}
}
?>

0 comments on commit 82e5323

Please sign in to comment.