Skip to content

Commit 402b34a

Browse files
committed
1 parent cb04a6e commit 402b34a

File tree

6 files changed

+73
-0
lines changed

6 files changed

+73
-0
lines changed

tests/PHPStan/Rules/Arrays/NonexistentOffsetInArrayDimFetchRuleTest.php

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

261+
public function testBug2689(): void
262+
{
263+
$this->analyse([__DIR__ . '/data/bug-2689.php'], [
264+
[
265+
'Cannot access an offset on callable.',
266+
14,
267+
],
268+
]);
269+
}
270+
261271
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace Bug2689;
4+
5+
class HelloWorld
6+
{
7+
/**
8+
* @var callable[]
9+
*/
10+
private $listeners;
11+
12+
public function addListener(string $name, callable $callback): void
13+
{
14+
$this->listeners[$name][] = $callback;
15+
}
16+
}

tests/PHPStan/Rules/Comparison/ImpossibleCheckTypeFunctionCallRuleTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,4 +392,11 @@ public function testBug1613(): void
392392
$this->analyse([__DIR__ . '/data/bug-1613.php'], []);
393393
}
394394

395+
public function testBug2714(): void
396+
{
397+
$this->checkAlwaysTrueCheckTypeFunctionCall = true;
398+
$this->treatPhpDocTypesAsCertain = true;
399+
$this->analyse([__DIR__ . '/data/bug-2714.php'], []);
400+
}
401+
395402
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
namespace Bug2714;
4+
5+
function (): void
6+
{
7+
$list = [];
8+
9+
// creation of unpredictable values at 'type' key
10+
for ($i = 0; $i < 3; $i++) {
11+
$list[] = [
12+
'type' => str_repeat('a', rand(1, 10)),
13+
];
14+
}
15+
16+
$list[] = [
17+
'type' => 'x',
18+
];
19+
20+
foreach ($list as $item) {
21+
if (in_array($item['type'], ['aaa', 'aaaa'], TRUE)) {
22+
echo 'OK';
23+
}
24+
}
25+
};

tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,4 +492,9 @@ public function testBug2434(): void
492492
$this->analyse([__DIR__ . '/data/bug-2434.php'], []);
493493
}
494494

495+
public function testBug2846(): void
496+
{
497+
$this->analyse([__DIR__ . '/data/bug-2846.php'], []);
498+
}
499+
495500
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
namespace Bug2846;
4+
5+
class Test {
6+
public static function staticFunc(): void {}
7+
public static function callStatic(): void {
8+
call_user_func([static::class, 'staticFunc']);
9+
}
10+
}

0 commit comments

Comments
 (0)