Skip to content

Commit a0a51ff

Browse files
authored
Remove usages of ArrayManipulator (#124)
1 parent 19871e4 commit a0a51ff

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/Rector/MethodCall/LumenRoutesStringMiddlewareToArrayRector.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
use PhpParser\Node\Expr\ArrayItem;
1010
use PhpParser\Node\Expr\MethodCall;
1111
use PhpParser\Node\Scalar\String_;
12-
use Rector\Core\NodeManipulator\ArrayManipulator;
1312
use Rector\Core\Rector\AbstractRector;
1413
use RectorLaravel\NodeAnalyzer\LumenRouteRegisteringMethodAnalyzer;
1514
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
@@ -21,7 +20,6 @@
2120
final class LumenRoutesStringMiddlewareToArrayRector extends AbstractRector
2221
{
2322
public function __construct(
24-
private readonly ArrayManipulator $arrayManipulator,
2523
private readonly LumenRouteRegisteringMethodAnalyzer $lumenRouteRegisteringMethodAnalyzer
2624
) {
2725
}
@@ -118,7 +116,7 @@ private function findItemInArrayByKey(Array_ $array, string $keyName): ?ArrayIte
118116
if (! $item instanceof ArrayItem) {
119117
continue;
120118
}
121-
if (! $this->arrayManipulator->hasKeyName($item, $keyName)) {
119+
if (! $this->hasKeyName($item, $keyName)) {
122120
continue;
123121
}
124122
$foundArrayItem = $array->items[$i];
@@ -136,7 +134,7 @@ private function replaceItemInArrayByKey(Array_ $array, ArrayItem $arrayItem, st
136134
if (! $item instanceof ArrayItem) {
137135
continue;
138136
}
139-
if (! $this->arrayManipulator->hasKeyName($item, $keyName)) {
137+
if (! $this->hasKeyName($item, $keyName)) {
140138
continue;
141139
}
142140
if (! $array->items[$i] instanceof ArrayItem) {
@@ -146,4 +144,13 @@ private function replaceItemInArrayByKey(Array_ $array, ArrayItem $arrayItem, st
146144
$array->items[$i] = $arrayItem;
147145
}
148146
}
147+
148+
private function hasKeyName(ArrayItem $arrayItem, string $name): bool
149+
{
150+
if (! $arrayItem->key instanceof String_) {
151+
return false;
152+
}
153+
154+
return $arrayItem->key->value === $name;
155+
}
149156
}

0 commit comments

Comments
 (0)