17
17
use PHPStan \Type \Accessory \NonEmptyArrayType ;
18
18
use PHPStan \Type \ArrayType ;
19
19
use PHPStan \Type \CallableType ;
20
- use PHPStan \Type \ClosureType ;
21
20
use PHPStan \Type \Constant \ConstantStringType ;
22
21
use PHPStan \Type \FloatType ;
23
22
use PHPStan \Type \IntegerRangeType ;
@@ -104,13 +103,13 @@ private function specifyAssertAll(MethodReflection $staticMethodReflection, Stat
104
103
$ callable = $ node ->getArgs ()[0 ]->value ;
105
104
$ callableInfo = $ scope ->getType ($ callable );
106
105
107
- if (!$ callableInfo instanceof ClosureType ) {
106
+ if (!$ callableInfo-> isCallable ()-> yes () ) {
108
107
return new SpecifiedTypes ();
109
108
}
110
109
111
110
return $ this ->typeSpecifier ->create (
112
111
$ node ->getArgs ()[1 ]->value ,
113
- new IterableType (new MixedType (true ), $ callableInfo -> getReturnType ()),
112
+ new IterableType (new MixedType (), new MixedType ()),
114
113
TypeSpecifierContext::createTruthy (),
115
114
false ,
116
115
$ scope ,
@@ -124,7 +123,7 @@ private function specifyAssertAllStrings(MethodReflection $staticMethodReflectio
124
123
{
125
124
return $ this ->typeSpecifier ->create (
126
125
$ node ->getArgs ()[0 ]->value ,
127
- new IterableType (new MixedType (true ), new StringType ()),
126
+ new IterableType (new MixedType (), new StringType ()),
128
127
TypeSpecifierContext::createTruthy (),
129
128
false ,
130
129
$ scope ,
@@ -138,7 +137,7 @@ private function specifyAssertAllStringable(MethodReflection $staticMethodReflec
138
137
{
139
138
// Drupal considers string as part of "stringable" as well.
140
139
$ stringable = TypeCombinator::union (new ObjectType (Stringable::class), new StringType ());
141
- $ newType = new IterableType (new MixedType (true ), $ stringable );
140
+ $ newType = new IterableType (new MixedType (), $ stringable );
142
141
143
142
return $ this ->typeSpecifier ->create (
144
143
$ node ->getArgs ()[0 ]->value ,
@@ -154,8 +153,8 @@ private function specifyAssertAllStringable(MethodReflection $staticMethodReflec
154
153
*/
155
154
private function specifyAssertAllArrays (MethodReflection $ staticMethodReflection , StaticCall $ node , Scope $ scope , TypeSpecifierContext $ context ): SpecifiedTypes
156
155
{
157
- $ arrayType = new ArrayType (new MixedType (true ), new MixedType (true ));
158
- $ newType = new IterableType (new MixedType (true ), $ arrayType );
156
+ $ arrayType = new ArrayType (new MixedType (), new MixedType ());
157
+ $ newType = new IterableType (new MixedType (), $ arrayType );
159
158
160
159
return $ this ->typeSpecifier ->create (
161
160
$ node ->getArgs ()[0 ]->value ,
@@ -175,7 +174,7 @@ private function specifyAssertStrictArray(MethodReflection $staticMethodReflecti
175
174
// In Drupal, 'strict arrays' are defined as arrays whose indexes
176
175
// consist of integers that are equal to or greater than 0.
177
176
IntegerRangeType::createAllGreaterThanOrEqualTo (0 ),
178
- new MixedType (true ),
177
+ new MixedType (),
179
178
);
180
179
181
180
return $ this ->typeSpecifier ->create (
@@ -193,10 +192,10 @@ private function specifyAssertStrictArray(MethodReflection $staticMethodReflecti
193
192
private function specifyAssertAllStrictArrays (MethodReflection $ staticMethodReflection , StaticCall $ node , Scope $ scope , TypeSpecifierContext $ context ): SpecifiedTypes
194
193
{
195
194
$ newType = new IterableType (
196
- new MixedType (true ),
195
+ new MixedType (),
197
196
new ArrayType (
198
197
IntegerRangeType::createAllGreaterThanOrEqualTo (0 ),
199
- new MixedType (true ),
198
+ new MixedType (),
200
199
),
201
200
);
202
201
@@ -235,17 +234,20 @@ private function specifyAssertAllHaveKey(MethodReflection $staticMethodReflectio
235
234
}
236
235
}
237
236
238
- $ keyTypes = [];
237
+ // @see ArrayKeyExistsFunctionTypeSpecifyingExtension.
238
+ $ possibleTypes = [
239
+ new ArrayType (new MixedType (), new MixedType ())
240
+ ];
239
241
foreach ($ keys as $ key ) {
240
- $ keyTypes [] = new HasOffsetType (new ConstantStringType ($ key ));
242
+ $ possibleTypes [] = new HasOffsetType (new ConstantStringType ($ key ));
241
243
}
242
244
243
- $ newArrayType = new ArrayType (
244
- new MixedType (true ),
245
- new ArrayType ( TypeCombinator::intersect (new MixedType (), ...$ keyTypes ), new MixedType ( true ) ),
245
+ $ newType = new IterableType (
246
+ new MixedType (),
247
+ TypeCombinator::intersect (...$ possibleTypes ),
246
248
);
247
249
248
- return $ this ->typeSpecifier ->create ($ traversableArg , $ newArrayType , TypeSpecifierContext::createTruthy (), false , $ scope );
250
+ return $ this ->typeSpecifier ->create ($ traversableArg , $ newType , TypeSpecifierContext::createTruthy (), false , $ scope );
249
251
}
250
252
251
253
/**
@@ -255,7 +257,7 @@ private function specifyAssertAllIntegers(MethodReflection $staticMethodReflecti
255
257
{
256
258
return $ this ->typeSpecifier ->create (
257
259
$ node ->getArgs ()[0 ]->value ,
258
- new IterableType (new MixedType (true ), new IntegerType ()),
260
+ new IterableType (new MixedType (), new IntegerType ()),
259
261
TypeSpecifierContext::createTruthy (),
260
262
false ,
261
263
$ scope ,
@@ -269,7 +271,7 @@ private function specifyAssertAllFloat(MethodReflection $staticMethodReflection,
269
271
{
270
272
return $ this ->typeSpecifier ->create (
271
273
$ node ->getArgs ()[0 ]->value ,
272
- new IterableType (new MixedType (true ), new FloatType ()),
274
+ new IterableType (new MixedType (), new FloatType ()),
273
275
TypeSpecifierContext::createTruthy (),
274
276
false ,
275
277
$ scope ,
@@ -283,7 +285,7 @@ private function specifyAssertAllCallable(MethodReflection $staticMethodReflecti
283
285
{
284
286
return $ this ->typeSpecifier ->create (
285
287
$ node ->getArgs ()[0 ]->value ,
286
- new IterableType (new MixedType (true ), new CallableType ()),
288
+ new IterableType (new MixedType (), new CallableType ()),
287
289
TypeSpecifierContext::createTruthy (),
288
290
false ,
289
291
$ scope ,
@@ -304,7 +306,7 @@ private function specifyAssertAllNotEmpty(MethodReflection $staticMethodReflecti
304
306
new FloatType (),
305
307
new ResourceType (),
306
308
];
307
- $ newType = new IterableType (new MixedType (true ), new UnionType ($ non_empty_types ));
309
+ $ newType = new IterableType (new MixedType (), new UnionType ($ non_empty_types ));
308
310
309
311
return $ this ->typeSpecifier ->create (
310
312
$ node ->getArgs ()[0 ]->value ,
@@ -322,7 +324,7 @@ private function specifyAssertAllNumeric(MethodReflection $staticMethodReflectio
322
324
{
323
325
return $ this ->typeSpecifier ->create (
324
326
$ node ->getArgs ()[0 ]->value ,
325
- new IterableType (new MixedType (true ), new UnionType ([new IntegerType (), new FloatType ()])),
327
+ new IterableType (new MixedType (), new UnionType ([new IntegerType (), new FloatType ()])),
326
328
TypeSpecifierContext::createTruthy (),
327
329
false ,
328
330
$ scope ,
@@ -336,7 +338,7 @@ private function specifyAssertAllMatch(MethodReflection $staticMethodReflection,
336
338
{
337
339
return $ this ->typeSpecifier ->create (
338
340
$ node ->getArgs ()[1 ]->value ,
339
- new IterableType (new MixedType (true ), new StringType ()),
341
+ new IterableType (new MixedType (), new StringType ()),
340
342
TypeSpecifierContext::createTruthy (),
341
343
false ,
342
344
$ scope ,
@@ -352,7 +354,7 @@ private function specifyAssertAllRegularExpressionMatch(MethodReflection $static
352
354
$ node ->getArgs ()[1 ]->value ,
353
355
// Drupal treats any non-string input in traversable as invalid
354
356
// value, so it is possible to narrow type here.
355
- new IterableType (new MixedType (true ), new StringType ()),
357
+ new IterableType (new MixedType (), new StringType ()),
356
358
TypeSpecifierContext::createTruthy (),
357
359
false ,
358
360
$ scope ,
@@ -386,7 +388,7 @@ private function specifyAssertAllObjects(MethodReflection $staticMethodReflectio
386
388
387
389
return $ this ->typeSpecifier ->create (
388
390
$ node ->getArgs ()[0 ]->value ,
389
- new IterableType (new MixedType (true ), TypeCombinator::union (...$ objectTypes )),
391
+ new IterableType (new MixedType (), TypeCombinator::union (...$ objectTypes )),
390
392
TypeSpecifierContext::createTruthy (),
391
393
false ,
392
394
$ scope ,
0 commit comments