|
2 | 2 |
|
3 | 3 | namespace PHPStan\Rules;
|
4 | 4 |
|
5 |
| -use function array_key_exists; |
| 5 | +use PHPStan\Reflection\ExtendedMethodReflection; |
6 | 6 | use function sprintf;
|
7 | 7 | use function ucfirst;
|
8 | 8 |
|
@@ -39,26 +39,26 @@ final class ClassNameUsageLocation
|
39 | 39 | public const PHPDOC_TAG_TEMPLATE_BOUND = 'templateBound';
|
40 | 40 | public const PHPDOC_TAG_TEMPLATE_DEFAULT = 'templateDefault';
|
41 | 41 |
|
42 |
| - /** @var array<string, self> */ |
43 |
| - public static array $registry = []; |
44 |
| - |
45 | 42 | /**
|
46 | 43 | * @param self::* $value
|
| 44 | + * @param mixed[] $data |
47 | 45 | */
|
48 |
| - private function __construct(public readonly string $value) |
| 46 | + private function __construct(public readonly string $value, public readonly array $data) |
49 | 47 | {
|
50 | 48 | }
|
51 | 49 |
|
52 | 50 | /**
|
53 | 51 | * @param self::* $value
|
| 52 | + * @param mixed[] $data |
54 | 53 | */
|
55 |
| - public static function from(string $value): self |
| 54 | + public static function from(string $value, array $data = []): self |
56 | 55 | {
|
57 |
| - if (array_key_exists($value, self::$registry)) { |
58 |
| - return self::$registry[$value]; |
59 |
| - } |
| 56 | + return new self($value, $data); |
| 57 | + } |
60 | 58 |
|
61 |
| - return self::$registry[$value] = new self($value); |
| 59 | + public function getMethod(): ?ExtendedMethodReflection |
| 60 | + { |
| 61 | + return $this->data['method'] ?? null; |
62 | 62 | }
|
63 | 63 |
|
64 | 64 | public function createMessage(string $part): string
|
@@ -111,6 +111,11 @@ public function createMessage(string $part): string
|
111 | 111 | case self::PHPDOC_TAG_REQUIRE_IMPLEMENTS:
|
112 | 112 | return sprintf('PHPDoc tag @phpstan-require-implements references %s.', $part);
|
113 | 113 | case self::STATIC_METHOD_CALL:
|
| 114 | + $method = $this->getMethod(); |
| 115 | + if ($method !== null) { |
| 116 | + return sprintf('Call to static method %s() on %s.', $method->getName(), $part); |
| 117 | + } |
| 118 | + |
114 | 119 | return sprintf('Call to static method on %s.', $part);
|
115 | 120 | case self::PHPDOC_TAG_TEMPLATE_BOUND:
|
116 | 121 | return sprintf('PHPDoc tag @template bound references %s.', $part);
|
|
0 commit comments