Skip to content

Commit 8d87c67

Browse files
VincentLangletondrejmirtes
authored andcommitted
Solve 11703
1 parent c107652 commit 8d87c67

File tree

2 files changed

+101
-2
lines changed

2 files changed

+101
-2
lines changed

src/Type/Accessory/OversizedArrayType.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,12 +227,12 @@ public function isIterable(): TrinaryLogic
227227

228228
public function isIterableAtLeastOnce(): TrinaryLogic
229229
{
230-
return TrinaryLogic::createYes();
230+
return TrinaryLogic::createMaybe();
231231
}
232232

233233
public function getArraySize(): Type
234234
{
235-
return IntegerRangeType::fromInterval(1, null);
235+
return IntegerRangeType::fromInterval(0, null);
236236
}
237237

238238
public function getIterableKeyType(): Type
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
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

Comments
 (0)