|
| 1 | +<?php declare(strict_types = 1); |
| 2 | + |
| 3 | +namespace Bug13509; |
| 4 | + |
| 5 | +use function PHPStan\Testing\assertType; |
| 6 | + |
| 7 | +/** @return ?array<string, mixed> */ |
| 8 | +function alert(): ?array |
| 9 | +{ |
| 10 | + $alerts = []; |
| 11 | + |
| 12 | + if (rand()) { |
| 13 | + $alerts[] = [ |
| 14 | + 'message' => "Foo", |
| 15 | + 'details' => "bar", |
| 16 | + 'duration' => rand() ?: null, |
| 17 | + 'severity' => 100, |
| 18 | + ]; |
| 19 | + } |
| 20 | + |
| 21 | + if (rand()) { |
| 22 | + $alerts[] = [ |
| 23 | + 'message' => 'Offline', |
| 24 | + 'duration' => rand() ?: null, |
| 25 | + 'severity' => 99, |
| 26 | + ]; |
| 27 | + } |
| 28 | + |
| 29 | + if (rand()) { |
| 30 | + $alerts[] = [ |
| 31 | + 'message' => 'Running W/O Operator', |
| 32 | + 'duration' => rand() ?: null, |
| 33 | + 'severity' => 75, |
| 34 | + ]; |
| 35 | + } |
| 36 | + |
| 37 | + if (rand()) { |
| 38 | + $alerts[] = [ |
| 39 | + 'message' => 'No Queue', |
| 40 | + 'duration' => rand() ?: null, |
| 41 | + 'severity' => 60, |
| 42 | + ]; |
| 43 | + } |
| 44 | + |
| 45 | + if (rand()) { |
| 46 | + if (rand()) { |
| 47 | + $alerts[] = [ |
| 48 | + 'message' => 'Not Scheduled', |
| 49 | + 'duration' => null, |
| 50 | + 'severity' => 25, |
| 51 | + ]; |
| 52 | + } |
| 53 | + |
| 54 | + if (rand()) { |
| 55 | + $alerts[] = [ |
| 56 | + 'message' => 'On Lunch', |
| 57 | + 'duration' => rand() ?: null, |
| 58 | + 'severity' => 24, |
| 59 | + ]; |
| 60 | + } |
| 61 | + |
| 62 | + if (rand()) { |
| 63 | + $alerts[] = [ |
| 64 | + 'message' => 'On Break', |
| 65 | + 'duration' => rand() ?: null, |
| 66 | + 'severity' => 24, |
| 67 | + ]; |
| 68 | + } |
| 69 | + } |
| 70 | + |
| 71 | + if (rand()) { |
| 72 | + $alerts[] = [ |
| 73 | + 'message' => 'Idle', |
| 74 | + 'duration' => rand() ?: null, |
| 75 | + 'severity' => 23, |
| 76 | + ]; |
| 77 | + } |
| 78 | + |
| 79 | + if ($alerts === []) { |
| 80 | + return null; |
| 81 | + } |
| 82 | + |
| 83 | + assertType('non-empty-list<non-empty-array<literal-string&lowercase-string&non-falsy-string, int|(literal-string&non-falsy-string)|null>&oversized-array>&oversized-array', $alerts); |
| 84 | + |
| 85 | + usort($alerts, fn ($a, $b) => $b['severity'] <=> $a['severity']); |
| 86 | + |
| 87 | + return $alerts[0]; |
| 88 | +} |
0 commit comments