Skip to content

Commit c6f8126

Browse files
committed
Added regression test
1 parent 745c099 commit c6f8126

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

tests/PHPStan/Rules/Comparison/NumberComparisonOperatorsConstantConditionRuleTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,4 +257,10 @@ public function testBug12716(): void
257257
$this->analyse([__DIR__ . '/data/bug-12716.php'], []);
258258
}
259259

260+
public function testBug3387(): void
261+
{
262+
$this->treatPhpDocTypesAsCertain = true;
263+
$this->analyse([__DIR__ . '/data/bug-3387.php'], []);
264+
}
265+
260266
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
namespace Bug3387;
4+
5+
function (array $items, string $key) {
6+
$array = [$key => []];
7+
foreach ($items as $item) {
8+
$array[$key][] = $item;
9+
if (count($array[$key]) > 1) {
10+
throw new RuntimeException();
11+
}
12+
}
13+
};
14+
15+
function (array $items, string $key) {
16+
$array = [$key => []];
17+
foreach ($items as $item) {
18+
array_unshift($array[$key], $item);
19+
if (count($array[$key]) > 1) {
20+
throw new RuntimeException();
21+
}
22+
}
23+
};
24+
25+
function (array $items, string $key) {
26+
$array = [$key => []];
27+
foreach ($items as $item) {
28+
array_push($array[$key], $item);
29+
if (count($array[$key]) > 1) {
30+
throw new RuntimeException();
31+
}
32+
}
33+
};

0 commit comments

Comments
 (0)