9
9
use PhpParser \Node \Expr \ArrayItem ;
10
10
use PhpParser \Node \Expr \MethodCall ;
11
11
use PhpParser \Node \Scalar \String_ ;
12
- use Rector \Core \NodeManipulator \ArrayManipulator ;
13
12
use Rector \Core \Rector \AbstractRector ;
14
13
use RectorLaravel \NodeAnalyzer \LumenRouteRegisteringMethodAnalyzer ;
15
14
use Symplify \RuleDocGenerator \ValueObject \CodeSample \CodeSample ;
21
20
final class LumenRoutesStringMiddlewareToArrayRector extends AbstractRector
22
21
{
23
22
public function __construct (
24
- private readonly ArrayManipulator $ arrayManipulator ,
25
23
private readonly LumenRouteRegisteringMethodAnalyzer $ lumenRouteRegisteringMethodAnalyzer
26
24
) {
27
25
}
@@ -118,7 +116,7 @@ private function findItemInArrayByKey(Array_ $array, string $keyName): ?ArrayIte
118
116
if (! $ item instanceof ArrayItem) {
119
117
continue ;
120
118
}
121
- if (! $ this ->arrayManipulator -> hasKeyName ($ item , $ keyName )) {
119
+ if (! $ this ->hasKeyName ($ item , $ keyName )) {
122
120
continue ;
123
121
}
124
122
$ foundArrayItem = $ array ->items [$ i ];
@@ -136,7 +134,7 @@ private function replaceItemInArrayByKey(Array_ $array, ArrayItem $arrayItem, st
136
134
if (! $ item instanceof ArrayItem) {
137
135
continue ;
138
136
}
139
- if (! $ this ->arrayManipulator -> hasKeyName ($ item , $ keyName )) {
137
+ if (! $ this ->hasKeyName ($ item , $ keyName )) {
140
138
continue ;
141
139
}
142
140
if (! $ array ->items [$ i ] instanceof ArrayItem) {
@@ -146,4 +144,13 @@ private function replaceItemInArrayByKey(Array_ $array, ArrayItem $arrayItem, st
146
144
$ array ->items [$ i ] = $ arrayItem ;
147
145
}
148
146
}
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
+ }
149
156
}
0 commit comments