diff --git a/tests/PHPStan/Rules/Functions/CallCallablesRuleTest.php b/tests/PHPStan/Rules/Functions/CallCallablesRuleTest.php index 837f9faf73..c82080b9ed 100644 --- a/tests/PHPStan/Rules/Functions/CallCallablesRuleTest.php +++ b/tests/PHPStan/Rules/Functions/CallCallablesRuleTest.php @@ -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'], [ diff --git a/tests/PHPStan/Rules/Functions/data/bug-3616.php b/tests/PHPStan/Rules/Functions/data/bug-3616.php new file mode 100644 index 0000000000..8b3304f3c3 --- /dev/null +++ b/tests/PHPStan/Rules/Functions/data/bug-3616.php @@ -0,0 +1,53 @@ + */ + 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])(); + } +}