|
| 1 | +<?php declare(strict_types = 1); |
| 2 | + |
| 3 | +namespace Bug11703; |
| 4 | + |
| 5 | +use function PHPStan\Testing\assertType; |
| 6 | + |
| 7 | +function test(int|string|null $duration, string $foo): ?bool |
| 8 | +{ |
| 9 | + $alerts = []; |
| 10 | + |
| 11 | + if (mt_rand(0, 1)) { |
| 12 | + $alerts[] = [ |
| 13 | + 'message' => 'Some message about the alert.', |
| 14 | + 'duration' => $duration, |
| 15 | + 'severity' => 100, |
| 16 | + ]; |
| 17 | + } |
| 18 | + |
| 19 | + if (mt_rand(0, 1)) { |
| 20 | + $alerts[] = [ |
| 21 | + 'message' => 'Some message about the alert2.', |
| 22 | + 'duration' => $duration, |
| 23 | + 'severity' => 99, |
| 24 | + ]; |
| 25 | + } |
| 26 | + |
| 27 | + if (mt_rand(0, 1)) { |
| 28 | + $alerts[] = [ |
| 29 | + 'message' => 'Some message about the alert3.', |
| 30 | + 'duration' => $duration, |
| 31 | + 'severity' => 75, |
| 32 | + ]; |
| 33 | + } |
| 34 | + |
| 35 | + if (mt_rand(0, 1)) { |
| 36 | + $alerts[] = [ |
| 37 | + 'message' => 'Some message about the alert4.', |
| 38 | + 'duration' => $duration, |
| 39 | + 'severity' => 60, |
| 40 | + ]; |
| 41 | + } |
| 42 | + |
| 43 | + if (mt_rand(0, 1)) { |
| 44 | + $alerts[] = [ |
| 45 | + 'message' => 'Some message about the alert5.', |
| 46 | + 'duration' => null, |
| 47 | + 'severity' => 25, |
| 48 | + ]; |
| 49 | + } |
| 50 | + |
| 51 | + if (mt_rand(0, 1)) { |
| 52 | + $alerts[] = [ |
| 53 | + 'message' => 'Some message about the alert6.', |
| 54 | + 'duration' => $duration, |
| 55 | + 'severity' => 24, |
| 56 | + ]; |
| 57 | + } |
| 58 | + |
| 59 | + if (mt_rand(0, 1)) { |
| 60 | + $alerts[] = [ |
| 61 | + 'message' => 'Some message about the alert7.', |
| 62 | + 'duration' => $duration, |
| 63 | + 'severity' => 24, |
| 64 | + ]; |
| 65 | + } |
| 66 | + |
| 67 | + if (mt_rand(0, 1)) { |
| 68 | + $alerts[] = [ |
| 69 | + 'message' => 'Some message about the alert8.', |
| 70 | + 'duration' => $duration, |
| 71 | + 'severity' => 24, |
| 72 | + ]; |
| 73 | + } |
| 74 | + |
| 75 | + if (mt_rand(0, 1)) { |
| 76 | + $alerts[] = [ |
| 77 | + 'message' => 'Some message about the alert9.', |
| 78 | + 'duration' => $duration, |
| 79 | + 'severity' => 24, |
| 80 | + ]; |
| 81 | + } |
| 82 | + |
| 83 | + assertType('int<0, 9>', count($alerts)); |
| 84 | + |
| 85 | + if (mt_rand(0, 1)) { |
| 86 | + $alerts[] = [ |
| 87 | + 'message' => 'Some message about the alert10.', |
| 88 | + 'duration' => $duration, |
| 89 | + 'severity' => 23, |
| 90 | + ]; |
| 91 | + } |
| 92 | + |
| 93 | + assertType('int<0, max>', count($alerts)); |
| 94 | + if (count($alerts) === 0) { |
| 95 | + return null; |
| 96 | + } |
| 97 | + |
| 98 | + return true; |
| 99 | +} |
0 commit comments