-
Notifications
You must be signed in to change notification settings - Fork 478
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix calling method statically on string
- Loading branch information
1 parent
ab0245c
commit 3aa878f
Showing
3 changed files
with
101 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<?php | ||
|
||
namespace Bug6404; | ||
|
||
|
||
use function PHPStan\Testing\assertType; | ||
|
||
class Foo | ||
{ | ||
public static function getCode(): int | ||
{ | ||
return 1; | ||
} | ||
} | ||
|
||
class Bar | ||
{ | ||
private const FOOS = [ | ||
Foo::class, | ||
]; | ||
|
||
/** | ||
* @var array<int, bool> | ||
*/ | ||
private array $someMap = []; | ||
|
||
public function build(): void | ||
{ | ||
foreach (self::FOOS as $fooClass) { | ||
if (is_a($fooClass, Foo::class, true)) { | ||
assertType("'Bug6404\\\\Foo'", $fooClass); | ||
assertType('int', $fooClass::getCode()); | ||
$this->someMap[$fooClass::getCode()] = true; | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* @param object[] $objects | ||
* @return void | ||
*/ | ||
public function build2(array $objects): void | ||
{ | ||
foreach ($objects as $fooClass) { | ||
if (is_a($fooClass, Foo::class)) { | ||
assertType(Foo::class, $fooClass); | ||
assertType('int', $fooClass::getCode()); | ||
$this->someMap[$fooClass::getCode()] = true; | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* @param mixed[] $mixeds | ||
* @return void | ||
*/ | ||
public function build3(array $mixeds): void | ||
{ | ||
foreach ($mixeds as $fooClass) { | ||
if (is_a($fooClass, Foo::class, true)) { | ||
assertType('Bug6404\\Foo|class-string<Bug6404\\Foo>', $fooClass); | ||
assertType('int', $fooClass::getCode()); | ||
$this->someMap[$fooClass::getCode()] = true; | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* @param class-string<Foo> $classString | ||
* @return void | ||
*/ | ||
public function doBar(string $classString): void | ||
{ | ||
assertType("class-string<" . Foo::class . ">", $classString); | ||
assertType('int', $classString::getCode()); | ||
} | ||
|
||
/** | ||
* @return array<int, bool> | ||
*/ | ||
public function getAll(): array | ||
{ | ||
return $this->someMap; | ||
} | ||
} |