@@ -80,90 +80,90 @@ public function provideMinPhpVersion(): int
8080 return PhpVersionFeature::ARRAY_FIRST_LAST ;
8181 }
8282
83- private function refactorArrayKeyPattern (ArrayDimFetch $ node ): ?FuncCall
83+ private function refactorArrayKeyPattern (ArrayDimFetch $ arrayDimFetch ): ?FuncCall
8484 {
85- if (! $ node ->dim instanceof FuncCall) {
85+ if (! $ arrayDimFetch ->dim instanceof FuncCall) {
8686 return null ;
8787 }
8888
89- if (! $ this ->isNames ($ node ->dim , [self ::ARRAY_KEY_FIRST , self ::ARRAY_KEY_LAST ])) {
89+ if (! $ this ->isNames ($ arrayDimFetch ->dim , [self ::ARRAY_KEY_FIRST , self ::ARRAY_KEY_LAST ])) {
9090 return null ;
9191 }
9292
93- if ($ node ->dim ->isFirstClassCallable ()) {
93+ if ($ arrayDimFetch ->dim ->isFirstClassCallable ()) {
9494 return null ;
9595 }
9696
97- if (count ($ node ->dim ->getArgs ()) !== 1 ) {
97+ if (count ($ arrayDimFetch ->dim ->getArgs ()) !== 1 ) {
9898 return null ;
9999 }
100100
101- if (! $ this ->nodeComparator ->areNodesEqual ($ node ->var , $ node ->dim ->getArgs ()[0 ]->value )) {
101+ if (! $ this ->nodeComparator ->areNodesEqual ($ arrayDimFetch ->var , $ arrayDimFetch ->dim ->getArgs ()[0 ]->value )) {
102102 return null ;
103103 }
104104
105- if ($ this ->shouldSkip ($ node , $ node ->var )) {
105+ if ($ this ->shouldSkip ($ arrayDimFetch , $ arrayDimFetch ->var )) {
106106 return null ;
107107 }
108108
109- $ functionName = $ this ->isName ($ node ->dim , self ::ARRAY_KEY_FIRST )
109+ $ functionName = $ this ->isName ($ arrayDimFetch ->dim , self ::ARRAY_KEY_FIRST )
110110 ? 'array_first '
111111 : 'array_last ' ;
112112
113- return $ this ->nodeFactory ->createFuncCall ($ functionName , [$ node ->var ]);
113+ return $ this ->nodeFactory ->createFuncCall ($ functionName , [$ arrayDimFetch ->var ]);
114114 }
115115
116- private function refactorArrayValuesPattern (ArrayDimFetch $ node ): ?FuncCall
116+ private function refactorArrayValuesPattern (ArrayDimFetch $ arrayDimFetch ): ?FuncCall
117117 {
118- if (! $ node ->var instanceof FuncCall) {
118+ if (! $ arrayDimFetch ->var instanceof FuncCall) {
119119 return null ;
120120 }
121121
122- if (! $ this ->isName ($ node ->var , 'array_values ' )) {
122+ if (! $ this ->isName ($ arrayDimFetch ->var , 'array_values ' )) {
123123 return null ;
124124 }
125125
126- if ($ node ->var ->isFirstClassCallable ()) {
126+ if ($ arrayDimFetch ->var ->isFirstClassCallable ()) {
127127 return null ;
128128 }
129129
130- if (count ($ node ->var ->getArgs ()) !== 1 ) {
130+ if (count ($ arrayDimFetch ->var ->getArgs ()) !== 1 ) {
131131 return null ;
132132 }
133133
134- if ($ this ->shouldSkip ($ node , $ node )) {
134+ if ($ this ->shouldSkip ($ arrayDimFetch , $ arrayDimFetch )) {
135135 return null ;
136136 }
137137
138- $ arrayArg = $ node ->var ->getArgs ()[0 ]
138+ $ arrayArg = $ arrayDimFetch ->var ->getArgs ()[0 ]
139139 ->value ;
140140
141- if ($ node ->dim instanceof Int_ && $ node ->dim ->value === 0 ) {
141+ if ($ arrayDimFetch ->dim instanceof Int_ && $ arrayDimFetch ->dim ->value === 0 ) {
142142 return $ this ->nodeFactory ->createFuncCall ('array_first ' , [$ arrayArg ]);
143143 }
144144
145- if ($ node ->dim instanceof Minus) {
146- if (! $ node ->dim ->left instanceof FuncCall) {
145+ if ($ arrayDimFetch ->dim instanceof Minus) {
146+ if (! $ arrayDimFetch ->dim ->left instanceof FuncCall) {
147147 return null ;
148148 }
149149
150- if (! $ this ->isName ($ node ->dim ->left , 'count ' )) {
150+ if (! $ this ->isName ($ arrayDimFetch ->dim ->left , 'count ' )) {
151151 return null ;
152152 }
153153
154- if ($ node ->dim ->left ->isFirstClassCallable ()) {
154+ if ($ arrayDimFetch ->dim ->left ->isFirstClassCallable ()) {
155155 return null ;
156156 }
157157
158- if (count ($ node ->dim ->left ->getArgs ()) !== 1 ) {
158+ if (count ($ arrayDimFetch ->dim ->left ->getArgs ()) !== 1 ) {
159159 return null ;
160160 }
161161
162- if (! $ node ->dim ->right instanceof Int_ || $ node ->dim ->right ->value !== 1 ) {
162+ if (! $ arrayDimFetch ->dim ->right instanceof Int_ || $ arrayDimFetch ->dim ->right ->value !== 1 ) {
163163 return null ;
164164 }
165165
166- if (! $ this ->nodeComparator ->areNodesEqual ($ arrayArg , $ node ->dim ->left ->getArgs ()[0 ]->value )) {
166+ if (! $ this ->nodeComparator ->areNodesEqual ($ arrayArg , $ arrayDimFetch ->dim ->left ->getArgs ()[0 ]->value )) {
167167 return null ;
168168 }
169169
@@ -173,17 +173,12 @@ private function refactorArrayValuesPattern(ArrayDimFetch $node): ?FuncCall
173173 return null ;
174174 }
175175
176- private function shouldSkip (ArrayDimFetch $ node , Node $ scopeNode ): bool
176+ private function shouldSkip (ArrayDimFetch $ arrayDimFetch , Node $ scopeNode ): bool
177177 {
178178 $ scope = ScopeFetcher::fetch ($ scopeNode );
179- if ($ scope ->isInExpressionAssign ($ node )) {
179+ if ($ scope ->isInExpressionAssign ($ arrayDimFetch )) {
180180 return true ;
181181 }
182-
183- if ($ node ->getAttribute (AttributeKey::IS_UNSET_VAR )) {
184- return true ;
185- }
186-
187- return false ;
182+ return (bool ) $ arrayDimFetch ->getAttribute (AttributeKey::IS_UNSET_VAR );
188183 }
189184}
0 commit comments