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