Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions tests/PHPStan/Rules/Functions/CallCallablesRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,11 @@ public function testBug9614(): void
$this->analyse([__DIR__ . '/data/bug-9614.php'], []);
}

public function testBug3616(): void
{
$this->analyse([__DIR__ . '/data/bug-3616.php'], []);
}

public function testBug10814(): void
{
$this->analyse([__DIR__ . '/data/bug-10814.php'], [
Expand Down
53 changes: 53 additions & 0 deletions tests/PHPStan/Rules/Functions/data/bug-3616.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php declare(strict_types = 1);

namespace Bug3616;

class Factory {
public static function a(): void { echo 'A'; }
public static function b(): void { echo 'B'; }
}

class HelloWorld
{
/** @var array<string, callable():void> */
const FACTORIES = [
'a' => [Factory::class, 'a'],
'b' => [Factory::class, 'b']
];

public function withLiteral(): void
{
(self::FACTORIES['a'])();
}

public function withVariable(string $id): void
{
if (!isset(self::FACTORIES[$id])) {
return;
}

(self::FACTORIES[$id])();
}
}

class HelloWorld2
{
const FACTORIES = [
'a' => [Factory::class, 'a'],
'b' => [Factory::class, 'b']
];

public function withLiteral(): void
{
(self::FACTORIES['a'])();
}

public function withVariable(string $id): void
{
if (!isset(self::FACTORIES[$id])) {
return;
}

(self::FACTORIES[$id])();
}
}
Loading