1: | <?php declare(strict_types = 1); |
2: | |
3: | namespace PHPStan\Type\Generic; |
4: | |
5: | use function sprintf; |
6: | |
7: | class TemplateTypeScope |
8: | { |
9: | |
10: | public static function createWithFunction(string $functionName): self |
11: | { |
12: | return new self(null, $functionName); |
13: | } |
14: | |
15: | public static function createWithMethod(string $className, string $functionName): self |
16: | { |
17: | return new self($className, $functionName); |
18: | } |
19: | |
20: | public static function createWithClass(string $className): self |
21: | { |
22: | return new self($className, null); |
23: | } |
24: | |
25: | private function __construct(private ?string $className, private ?string $functionName) |
26: | { |
27: | } |
28: | |
29: | |
30: | public function getClassName(): ?string |
31: | { |
32: | return $this->className; |
33: | } |
34: | |
35: | |
36: | public function getFunctionName(): ?string |
37: | { |
38: | return $this->functionName; |
39: | } |
40: | |
41: | |
42: | public function equals(self $other): bool |
43: | { |
44: | return $this->className === $other->className |
45: | && $this->functionName === $other->functionName; |
46: | } |
47: | |
48: | |
49: | public function describe(): string |
50: | { |
51: | if ($this->className === null) { |
52: | return sprintf('function %s()', $this->functionName); |
53: | } |
54: | |
55: | if ($this->functionName === null) { |
56: | return sprintf('class %s', $this->className); |
57: | } |
58: | |
59: | return sprintf('method %s::%s()', $this->className, $this->functionName); |
60: | } |
61: | |
62: | |
63: | |
64: | |
65: | public static function __set_state(array $properties): self |
66: | { |
67: | return new self( |
68: | $properties['className'], |
69: | $properties['functionName'], |
70: | ); |
71: | } |
72: | |
73: | } |
74: | |