Skip to content

Add non regression test for 3616 #4175

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: 2.1.x
Choose a base branch
from
Open
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> */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add HelloWorld2 without the PHPDoc.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

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