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
$ scope ,
116
115
);
@@ -123,7 +122,7 @@ private function specifyAssertAllStrings(MethodReflection $staticMethodReflectio
123
122
{
124
123
return $ this ->typeSpecifier ->create (
125
124
$ node ->getArgs ()[0 ]->value ,
126
- new IterableType (new MixedType (true ), new StringType ()),
125
+ new IterableType (new MixedType (), new StringType ()),
127
126
TypeSpecifierContext::createTruthy (),
128
127
$ scope ,
129
128
);
@@ -136,7 +135,7 @@ private function specifyAssertAllStringable(MethodReflection $staticMethodReflec
136
135
{
137
136
// Drupal considers string as part of "stringable" as well.
138
137
$ stringable = TypeCombinator::union (new ObjectType (Stringable::class), new StringType ());
139
- $ newType = new IterableType (new MixedType (true ), $ stringable );
138
+ $ newType = new IterableType (new MixedType (), $ stringable );
140
139
141
140
return $ this ->typeSpecifier ->create (
142
141
$ node ->getArgs ()[0 ]->value ,
@@ -151,8 +150,8 @@ private function specifyAssertAllStringable(MethodReflection $staticMethodReflec
151
150
*/
152
151
private function specifyAssertAllArrays (MethodReflection $ staticMethodReflection , StaticCall $ node , Scope $ scope , TypeSpecifierContext $ context ): SpecifiedTypes
153
152
{
154
- $ arrayType = new ArrayType (new MixedType (true ), new MixedType (true ));
155
- $ newType = new IterableType (new MixedType (true ), $ arrayType );
153
+ $ arrayType = new ArrayType (new MixedType (), new MixedType ());
154
+ $ newType = new IterableType (new MixedType (), $ arrayType );
156
155
157
156
return $ this ->typeSpecifier ->create (
158
157
$ node ->getArgs ()[0 ]->value ,
@@ -171,7 +170,7 @@ private function specifyAssertStrictArray(MethodReflection $staticMethodReflecti
171
170
// In Drupal, 'strict arrays' are defined as arrays whose indexes
172
171
// consist of integers that are equal to or greater than 0.
173
172
IntegerRangeType::createAllGreaterThanOrEqualTo (0 ),
174
- new MixedType (true ),
173
+ new MixedType (),
175
174
);
176
175
177
176
return $ this ->typeSpecifier ->create (
@@ -188,10 +187,10 @@ private function specifyAssertStrictArray(MethodReflection $staticMethodReflecti
188
187
private function specifyAssertAllStrictArrays (MethodReflection $ staticMethodReflection , StaticCall $ node , Scope $ scope , TypeSpecifierContext $ context ): SpecifiedTypes
189
188
{
190
189
$ newType = new IterableType (
191
- new MixedType (true ),
190
+ new MixedType (),
192
191
new ArrayType (
193
192
IntegerRangeType::createAllGreaterThanOrEqualTo (0 ),
194
- new MixedType (true ),
193
+ new MixedType (),
195
194
),
196
195
);
197
196
@@ -229,17 +228,20 @@ private function specifyAssertAllHaveKey(MethodReflection $staticMethodReflectio
229
228
}
230
229
}
231
230
232
- $ keyTypes = [];
231
+ // @see ArrayKeyExistsFunctionTypeSpecifyingExtension.
232
+ $ possibleTypes = [
233
+ new ArrayType (new MixedType (), new MixedType ())
234
+ ];
233
235
foreach ($ keys as $ key ) {
234
- $ keyTypes [] = new HasOffsetType (new ConstantStringType ($ key ));
236
+ $ possibleTypes [] = new HasOffsetType (new ConstantStringType ($ key ));
235
237
}
236
238
237
- $ newArrayType = new ArrayType (
238
- new MixedType (true ),
239
- new ArrayType ( TypeCombinator::intersect (new MixedType (), ...$ keyTypes ), new MixedType ( true ) ),
239
+ $ newType = new IterableType (
240
+ new MixedType (),
241
+ TypeCombinator::intersect (...$ possibleTypes ),
240
242
);
241
243
242
- return $ this ->typeSpecifier ->create ($ traversableArg , $ newArrayType , TypeSpecifierContext::createTruthy (), $ scope );
244
+ return $ this ->typeSpecifier ->create ($ traversableArg , $ newType , TypeSpecifierContext::createTruthy (), $ scope );
243
245
}
244
246
245
247
/**
@@ -249,7 +251,7 @@ private function specifyAssertAllIntegers(MethodReflection $staticMethodReflecti
249
251
{
250
252
return $ this ->typeSpecifier ->create (
251
253
$ node ->getArgs ()[0 ]->value ,
252
- new IterableType (new MixedType (true ), new IntegerType ()),
254
+ new IterableType (new MixedType (), new IntegerType ()),
253
255
TypeSpecifierContext::createTruthy (),
254
256
$ scope ,
255
257
);
@@ -262,7 +264,7 @@ private function specifyAssertAllFloat(MethodReflection $staticMethodReflection,
262
264
{
263
265
return $ this ->typeSpecifier ->create (
264
266
$ node ->getArgs ()[0 ]->value ,
265
- new IterableType (new MixedType (true ), new FloatType ()),
267
+ new IterableType (new MixedType (), new FloatType ()),
266
268
TypeSpecifierContext::createTruthy (),
267
269
$ scope ,
268
270
);
@@ -275,7 +277,7 @@ private function specifyAssertAllCallable(MethodReflection $staticMethodReflecti
275
277
{
276
278
return $ this ->typeSpecifier ->create (
277
279
$ node ->getArgs ()[0 ]->value ,
278
- new IterableType (new MixedType (true ), new CallableType ()),
280
+ new IterableType (new MixedType (), new CallableType ()),
279
281
TypeSpecifierContext::createTruthy (),
280
282
$ scope ,
281
283
);
@@ -295,7 +297,7 @@ private function specifyAssertAllNotEmpty(MethodReflection $staticMethodReflecti
295
297
new FloatType (),
296
298
new ResourceType (),
297
299
];
298
- $ newType = new IterableType (new MixedType (true ), new UnionType ($ non_empty_types ));
300
+ $ newType = new IterableType (new MixedType (), new UnionType ($ non_empty_types ));
299
301
300
302
return $ this ->typeSpecifier ->create (
301
303
$ node ->getArgs ()[0 ]->value ,
@@ -312,7 +314,7 @@ private function specifyAssertAllNumeric(MethodReflection $staticMethodReflectio
312
314
{
313
315
return $ this ->typeSpecifier ->create (
314
316
$ node ->getArgs ()[0 ]->value ,
315
- new IterableType (new MixedType (true ), new UnionType ([new IntegerType (), new FloatType ()])),
317
+ new IterableType (new MixedType (), new UnionType ([new IntegerType (), new FloatType ()])),
316
318
TypeSpecifierContext::createTruthy (),
317
319
$ scope ,
318
320
);
@@ -325,7 +327,7 @@ private function specifyAssertAllMatch(MethodReflection $staticMethodReflection,
325
327
{
326
328
return $ this ->typeSpecifier ->create (
327
329
$ node ->getArgs ()[1 ]->value ,
328
- new IterableType (new MixedType (true ), new StringType ()),
330
+ new IterableType (new MixedType (), new StringType ()),
329
331
TypeSpecifierContext::createTruthy (),
330
332
$ scope ,
331
333
);
@@ -340,7 +342,7 @@ private function specifyAssertAllRegularExpressionMatch(MethodReflection $static
340
342
$ node ->getArgs ()[1 ]->value ,
341
343
// Drupal treats any non-string input in traversable as invalid
342
344
// value, so it is possible to narrow type here.
343
- new IterableType (new MixedType (true ), new StringType ()),
345
+ new IterableType (new MixedType (), new StringType ()),
344
346
TypeSpecifierContext::createTruthy (),
345
347
$ scope ,
346
348
);
@@ -373,7 +375,7 @@ private function specifyAssertAllObjects(MethodReflection $staticMethodReflectio
373
375
374
376
return $ this ->typeSpecifier ->create (
375
377
$ node ->getArgs ()[0 ]->value ,
376
- new IterableType (new MixedType (true ), TypeCombinator::union (...$ objectTypes )),
378
+ new IterableType (new MixedType (), TypeCombinator::union (...$ objectTypes )),
377
379
TypeSpecifierContext::createTruthy (),
378
380
$ scope ,
379
381
);
0 commit comments