Skip to content

Commit

Permalink
add test for bug 9465
Browse files Browse the repository at this point in the history
  • Loading branch information
schlndh committed Mar 17, 2024
1 parent bb113b1 commit 03edf69
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
7 changes: 7 additions & 0 deletions tests/PHPStan/Rules/Methods/CallStaticMethodsRuleTest.php
Expand Up @@ -824,4 +824,11 @@ public function testBugInstanceofStaticVsThis(): void
$this->analyse([__DIR__ . '/data/bug-instanceof-static-vs-this.php'], []);
}

public function testBug9465(): void
{
$this->checkThisOnly = false;
$this->checkExplicitMixed = true;
$this->analyse([__DIR__ . '/data/bug-9465.php'], []);
}

}
49 changes: 49 additions & 0 deletions tests/PHPStan/Rules/Methods/data/bug-9465.php
@@ -0,0 +1,49 @@
<?php declare(strict_types=1);

namespace Bug9465;

interface ISingleton
{
public static function singleton(): ?static;
}

class Component
{
public function getStuff(): mixed
{
return [1, 2, 3];
}

/**
* @param mixed[] $args
*/
public static function __callStatic(string $method, array $args): mixed
{
if (is_a(static::class, ISingleton::class, true) && ($singleton = static::singleton())) {
//Call to an undefined static method static(Component)::singleton().

$singleton->getStuff();
}
return null;
}
}

/**
* @method static void unavailableStatic()
*/
class Application extends Component implements ISingleton
{
protected static Application $_app;

public function __construct()
{
static::$_app = $this;
}

public static function singleton(): ?static
{
return static::$_app; //<- Method Application::singleton() should return static(Application)|null but returns Application.
}
}

Application::unavailableStatic();

0 comments on commit 03edf69

Please sign in to comment.