@@ -177,34 +177,12 @@ public function findSpecifiedType(
177
177
$ sureTypes = $ specifiedTypes ->getSureTypes ();
178
178
$ sureNotTypes = $ specifiedTypes ->getSureNotTypes ();
179
179
180
- $ isSpecified = static function (Expr $ expr ) use ($ scope , $ node ): bool {
181
- if ($ expr === $ node ) {
182
- return true ;
183
- }
184
-
185
- if ($ expr instanceof Expr \Variable && is_string ($ expr ->name ) && !$ scope ->hasVariableType ($ expr ->name )->yes ()) {
186
- return true ;
187
- }
188
-
189
- return (
190
- $ node instanceof FuncCall
191
- || $ node instanceof MethodCall
192
- || $ node instanceof Expr \StaticCall
193
- ) && $ scope ->isSpecified ($ expr );
194
- };
195
-
196
180
$ rootExpr = $ specifiedTypes ->getRootExpr ();
197
181
if ($ rootExpr !== null ) {
198
- if ($ isSpecified ($ rootExpr )) {
182
+ if (self :: isSpecified ($ scope , $ node , $ rootExpr )) {
199
183
return null ;
200
184
}
201
185
202
- if ($ rootExpr instanceof Expr \BinaryOp) {
203
- if ($ isSpecified ($ rootExpr ->left ) || $ isSpecified ($ rootExpr ->right )) {
204
- return null ;
205
- }
206
- }
207
-
208
186
$ rootExprType = $ scope ->getType ($ rootExpr );
209
187
if ($ rootExprType instanceof ConstantBooleanType) {
210
188
return $ rootExprType ->getValue ();
@@ -215,7 +193,7 @@ public function findSpecifiedType(
215
193
216
194
if (count ($ sureTypes ) === 1 && count ($ sureNotTypes ) === 0 ) {
217
195
$ sureType = reset ($ sureTypes );
218
- if ($ isSpecified ($ sureType [0 ])) {
196
+ if (self :: isSpecified ($ scope , $ node , $ sureType [0 ])) {
219
197
return null ;
220
198
}
221
199
@@ -238,7 +216,7 @@ public function findSpecifiedType(
238
216
return null ;
239
217
} elseif (count ($ sureNotTypes ) === 1 && count ($ sureTypes ) === 0 ) {
240
218
$ sureNotType = reset ($ sureNotTypes );
241
- if ($ isSpecified ($ sureNotType [0 ])) {
219
+ if (self :: isSpecified ($ scope , $ node , $ sureNotType [0 ])) {
242
220
return null ;
243
221
}
244
222
@@ -263,7 +241,7 @@ public function findSpecifiedType(
263
241
264
242
if (count ($ sureTypes ) > 0 ) {
265
243
foreach ($ sureTypes as $ sureType ) {
266
- if ($ isSpecified ($ sureType [0 ])) {
244
+ if (self :: isSpecified ($ scope , $ node , $ sureType [0 ])) {
267
245
return null ;
268
246
}
269
247
}
@@ -277,7 +255,7 @@ public function findSpecifiedType(
277
255
278
256
if (count ($ sureNotTypes ) > 0 ) {
279
257
foreach ($ sureNotTypes as $ sureNotType ) {
280
- if ($ isSpecified ($ sureNotType [0 ])) {
258
+ if (self :: isSpecified ($ scope , $ node , $ sureNotType [0 ])) {
281
259
return null ;
282
260
}
283
261
}
@@ -292,6 +270,31 @@ public function findSpecifiedType(
292
270
return null ;
293
271
}
294
272
273
+ private static function isSpecified (Scope $ scope , Expr $ node , Expr $ expr ): bool
274
+ {
275
+ if ($ expr === $ node ) {
276
+ return true ;
277
+ }
278
+
279
+ if ($ expr instanceof Expr \Variable && is_string ($ expr ->name ) && !$ scope ->hasVariableType ($ expr ->name )->yes ()) {
280
+ return true ;
281
+ }
282
+
283
+ if ($ expr instanceof Expr \BooleanNot) {
284
+ return self ::isSpecified ($ scope , $ node , $ expr ->expr );
285
+ }
286
+
287
+ if ($ expr instanceof Expr \BinaryOp) {
288
+ return self ::isSpecified ($ scope , $ node , $ expr ->left ) || self ::isSpecified ($ scope , $ node , $ expr ->right );
289
+ }
290
+
291
+ return (
292
+ $ node instanceof FuncCall
293
+ || $ node instanceof MethodCall
294
+ || $ node instanceof Expr \StaticCall
295
+ ) && $ scope ->isSpecified ($ expr );
296
+ }
297
+
295
298
/**
296
299
* @param Node\Arg[] $args
297
300
*/
0 commit comments