Skip to content

Commit 0da1ebc

Browse files
mitelgsebastianbergmann
authored andcommitted
fix: PHPStan detecting type correctly after usage of Assert::assertContainsOnly*
1 parent e7d19da commit 0da1ebc

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

src/Framework/Assert.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,8 @@ final public static function assertContainsOnly(string $type, iterable $haystack
294294
/**
295295
* Asserts that a haystack contains only values of type array.
296296
*
297+
* @phpstan-assert iterable<array<mixed>> $haystack
298+
*
297299
* @param iterable<mixed> $haystack
298300
*
299301
* @throws ExpectationFailedException
@@ -312,6 +314,8 @@ final public static function assertContainsOnlyArray(iterable $haystack, string
312314
/**
313315
* Asserts that a haystack contains only values of type bool.
314316
*
317+
* @phpstan-assert iterable<bool> $haystack
318+
*
315319
* @param iterable<mixed> $haystack
316320
*
317321
* @throws ExpectationFailedException
@@ -330,6 +334,8 @@ final public static function assertContainsOnlyBool(iterable $haystack, string $
330334
/**
331335
* Asserts that a haystack contains only values of type callable.
332336
*
337+
* @phpstan-assert iterable<callable> $haystack
338+
*
333339
* @param iterable<mixed> $haystack
334340
*
335341
* @throws ExpectationFailedException
@@ -348,6 +354,8 @@ final public static function assertContainsOnlyCallable(iterable $haystack, stri
348354
/**
349355
* Asserts that a haystack contains only values of type float.
350356
*
357+
* @phpstan-assert iterable<float> $haystack
358+
*
351359
* @param iterable<mixed> $haystack
352360
*
353361
* @throws ExpectationFailedException
@@ -366,6 +374,8 @@ final public static function assertContainsOnlyFloat(iterable $haystack, string
366374
/**
367375
* Asserts that a haystack contains only values of type int.
368376
*
377+
* @phpstan-assert iterable<int> $haystack
378+
*
369379
* @param iterable<mixed> $haystack
370380
*
371381
* @throws ExpectationFailedException
@@ -384,6 +394,8 @@ final public static function assertContainsOnlyInt(iterable $haystack, string $m
384394
/**
385395
* Asserts that a haystack contains only values of type iterable.
386396
*
397+
* @phpstan-assert iterable<iterable<mixed>> $haystack
398+
*
387399
* @param iterable<mixed> $haystack
388400
*
389401
* @throws ExpectationFailedException
@@ -402,6 +414,8 @@ final public static function assertContainsOnlyIterable(iterable $haystack, stri
402414
/**
403415
* Asserts that a haystack contains only values of type null.
404416
*
417+
* @phpstan-assert iterable<null> $haystack
418+
*
405419
* @param iterable<mixed> $haystack
406420
*
407421
* @throws ExpectationFailedException
@@ -420,6 +434,8 @@ final public static function assertContainsOnlyNull(iterable $haystack, string $
420434
/**
421435
* Asserts that a haystack contains only values of type numeric.
422436
*
437+
* @phpstan-assert iterable<numeric> $haystack
438+
*
423439
* @param iterable<mixed> $haystack
424440
*
425441
* @throws ExpectationFailedException
@@ -438,6 +454,8 @@ final public static function assertContainsOnlyNumeric(iterable $haystack, strin
438454
/**
439455
* Asserts that a haystack contains only values of type object.
440456
*
457+
* @phpstan-assert iterable<object> $haystack
458+
*
441459
* @param iterable<mixed> $haystack
442460
*
443461
* @throws ExpectationFailedException
@@ -456,6 +474,8 @@ final public static function assertContainsOnlyObject(iterable $haystack, string
456474
/**
457475
* Asserts that a haystack contains only values of type resource.
458476
*
477+
* @phpstan-assert iterable<resource> $haystack
478+
*
459479
* @param iterable<mixed> $haystack
460480
*
461481
* @throws ExpectationFailedException
@@ -474,6 +494,8 @@ final public static function assertContainsOnlyResource(iterable $haystack, stri
474494
/**
475495
* Asserts that a haystack contains only values of type closed resource.
476496
*
497+
* @phpstan-assert iterable<resource> $haystack
498+
*
477499
* @param iterable<mixed> $haystack
478500
*
479501
* @throws ExpectationFailedException
@@ -492,6 +514,8 @@ final public static function assertContainsOnlyClosedResource(iterable $haystack
492514
/**
493515
* Asserts that a haystack contains only values of type scalar.
494516
*
517+
* @phpstan-assert iterable<scalar> $haystack
518+
*
495519
* @param iterable<mixed> $haystack
496520
*
497521
* @throws ExpectationFailedException
@@ -510,6 +534,8 @@ final public static function assertContainsOnlyScalar(iterable $haystack, string
510534
/**
511535
* Asserts that a haystack contains only values of type string.
512536
*
537+
* @phpstan-assert iterable<string> $haystack
538+
*
513539
* @param iterable<mixed> $haystack
514540
*
515541
* @throws ExpectationFailedException

src/Framework/Assert/Functions.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,8 @@ function assertContainsOnly(string $type, iterable $haystack, ?bool $isNativeTyp
303303
/**
304304
* Asserts that a haystack contains only values of type array.
305305
*
306+
* @phpstan-assert iterable<array<mixed>> $haystack
307+
*
306308
* @param iterable<mixed> $haystack
307309
*
308310
* @throws ExpectationFailedException
@@ -321,6 +323,8 @@ function assertContainsOnlyArray(iterable $haystack, string $message = ''): void
321323
/**
322324
* Asserts that a haystack contains only values of type bool.
323325
*
326+
* @phpstan-assert iterable<bool> $haystack
327+
*
324328
* @param iterable<mixed> $haystack
325329
*
326330
* @throws ExpectationFailedException
@@ -339,6 +343,8 @@ function assertContainsOnlyBool(iterable $haystack, string $message = ''): void
339343
/**
340344
* Asserts that a haystack contains only values of type callable.
341345
*
346+
* @phpstan-assert iterable<callable> $haystack
347+
*
342348
* @param iterable<mixed> $haystack
343349
*
344350
* @throws ExpectationFailedException
@@ -357,6 +363,8 @@ function assertContainsOnlyCallable(iterable $haystack, string $message = ''): v
357363
/**
358364
* Asserts that a haystack contains only values of type float.
359365
*
366+
* @phpstan-assert iterable<float> $haystack
367+
*
360368
* @param iterable<mixed> $haystack
361369
*
362370
* @throws ExpectationFailedException
@@ -375,6 +383,8 @@ function assertContainsOnlyFloat(iterable $haystack, string $message = ''): void
375383
/**
376384
* Asserts that a haystack contains only values of type int.
377385
*
386+
* @phpstan-assert iterable<int> $haystack
387+
*
378388
* @param iterable<mixed> $haystack
379389
*
380390
* @throws ExpectationFailedException
@@ -393,6 +403,8 @@ function assertContainsOnlyInt(iterable $haystack, string $message = ''): void
393403
/**
394404
* Asserts that a haystack contains only values of type iterable.
395405
*
406+
* @phpstan-assert iterable<iterable<mixed>> $haystack
407+
*
396408
* @param iterable<mixed> $haystack
397409
*
398410
* @throws ExpectationFailedException
@@ -411,6 +423,8 @@ function assertContainsOnlyIterable(iterable $haystack, string $message = ''): v
411423
/**
412424
* Asserts that a haystack contains only values of type null.
413425
*
426+
* @phpstan-assert iterable<null> $haystack
427+
*
414428
* @param iterable<mixed> $haystack
415429
*
416430
* @throws ExpectationFailedException
@@ -429,6 +443,8 @@ function assertContainsOnlyNull(iterable $haystack, string $message = ''): void
429443
/**
430444
* Asserts that a haystack contains only values of type numeric.
431445
*
446+
* @phpstan-assert iterable<numeric> $haystack
447+
*
432448
* @param iterable<mixed> $haystack
433449
*
434450
* @throws ExpectationFailedException
@@ -447,6 +463,8 @@ function assertContainsOnlyNumeric(iterable $haystack, string $message = ''): vo
447463
/**
448464
* Asserts that a haystack contains only values of type object.
449465
*
466+
* @phpstan-assert iterable<object> $haystack
467+
*
450468
* @param iterable<mixed> $haystack
451469
*
452470
* @throws ExpectationFailedException
@@ -465,6 +483,8 @@ function assertContainsOnlyObject(iterable $haystack, string $message = ''): voi
465483
/**
466484
* Asserts that a haystack contains only values of type resource.
467485
*
486+
* @phpstan-assert iterable<resource> $haystack
487+
*
468488
* @param iterable<mixed> $haystack
469489
*
470490
* @throws ExpectationFailedException
@@ -483,6 +503,8 @@ function assertContainsOnlyResource(iterable $haystack, string $message = ''): v
483503
/**
484504
* Asserts that a haystack contains only values of type closed resource.
485505
*
506+
* @phpstan-assert iterable<resource> $haystack
507+
*
486508
* @param iterable<mixed> $haystack
487509
*
488510
* @throws ExpectationFailedException
@@ -501,6 +523,8 @@ function assertContainsOnlyClosedResource(iterable $haystack, string $message =
501523
/**
502524
* Asserts that a haystack contains only values of type scalar.
503525
*
526+
* @phpstan-assert iterable<scalar> $haystack
527+
*
504528
* @param iterable<mixed> $haystack
505529
*
506530
* @throws ExpectationFailedException
@@ -519,6 +543,8 @@ function assertContainsOnlyScalar(iterable $haystack, string $message = ''): voi
519543
/**
520544
* Asserts that a haystack contains only values of type string.
521545
*
546+
* @phpstan-assert iterable<string> $haystack
547+
*
522548
* @param iterable<mixed> $haystack
523549
*
524550
* @throws ExpectationFailedException

0 commit comments

Comments
 (0)