| 1: | <?php declare(strict_types = 1); |
| 2: | |
| 3: | namespace PHPStan\Broker; |
| 4: | |
| 5: | use PhpParser\Node; |
| 6: | use PHPStan\Analyser\Scope; |
| 7: | use PHPStan\Reflection\ClassReflection; |
| 8: | use PHPStan\Reflection\FunctionReflection; |
| 9: | use PHPStan\Reflection\GlobalConstantReflection; |
| 10: | use PHPStan\Reflection\NamespaceAnswerer; |
| 11: | use PHPStan\Reflection\ReflectionProvider; |
| 12: | use PHPStan\ShouldNotHappenException; |
| 13: | |
| 14: | |
| 15: | class Broker implements ReflectionProvider |
| 16: | { |
| 17: | |
| 18: | private static ?Broker $instance = null; |
| 19: | |
| 20: | |
| 21: | |
| 22: | |
| 23: | public function __construct( |
| 24: | private ReflectionProvider $reflectionProvider, |
| 25: | private array $universalObjectCratesClasses, |
| 26: | ) |
| 27: | { |
| 28: | } |
| 29: | |
| 30: | public static function registerInstance(Broker $broker): void |
| 31: | { |
| 32: | self::$instance = $broker; |
| 33: | } |
| 34: | |
| 35: | |
| 36: | |
| 37: | |
| 38: | public static function getInstance(): Broker |
| 39: | { |
| 40: | if (self::$instance === null) { |
| 41: | throw new ShouldNotHappenException(); |
| 42: | } |
| 43: | return self::$instance; |
| 44: | } |
| 45: | |
| 46: | |
| 47: | |
| 48: | |
| 49: | public function hasClass(string $className): bool |
| 50: | { |
| 51: | return $this->reflectionProvider->hasClass($className); |
| 52: | } |
| 53: | |
| 54: | |
| 55: | |
| 56: | |
| 57: | public function getClass(string $className): ClassReflection |
| 58: | { |
| 59: | return $this->reflectionProvider->getClass($className); |
| 60: | } |
| 61: | |
| 62: | |
| 63: | |
| 64: | |
| 65: | public function getClassName(string $className): string |
| 66: | { |
| 67: | return $this->reflectionProvider->getClassName($className); |
| 68: | } |
| 69: | |
| 70: | |
| 71: | |
| 72: | |
| 73: | public function supportsAnonymousClasses(): bool |
| 74: | { |
| 75: | return $this->reflectionProvider->supportsAnonymousClasses(); |
| 76: | } |
| 77: | |
| 78: | |
| 79: | |
| 80: | |
| 81: | public function getAnonymousClassReflection(Node\Stmt\Class_ $classNode, Scope $scope): ClassReflection |
| 82: | { |
| 83: | return $this->reflectionProvider->getAnonymousClassReflection($classNode, $scope); |
| 84: | } |
| 85: | |
| 86: | |
| 87: | |
| 88: | |
| 89: | public function hasFunction(Node\Name $nameNode, ?NamespaceAnswerer $namespaceAnswerer): bool |
| 90: | { |
| 91: | return $this->reflectionProvider->hasFunction($nameNode, $namespaceAnswerer); |
| 92: | } |
| 93: | |
| 94: | |
| 95: | |
| 96: | |
| 97: | public function getFunction(Node\Name $nameNode, ?NamespaceAnswerer $namespaceAnswerer): FunctionReflection |
| 98: | { |
| 99: | return $this->reflectionProvider->getFunction($nameNode, $namespaceAnswerer); |
| 100: | } |
| 101: | |
| 102: | |
| 103: | |
| 104: | |
| 105: | public function resolveFunctionName(Node\Name $nameNode, ?NamespaceAnswerer $namespaceAnswerer): ?string |
| 106: | { |
| 107: | return $this->reflectionProvider->resolveFunctionName($nameNode, $namespaceAnswerer); |
| 108: | } |
| 109: | |
| 110: | |
| 111: | |
| 112: | |
| 113: | public function hasConstant(Node\Name $nameNode, ?NamespaceAnswerer $namespaceAnswerer): bool |
| 114: | { |
| 115: | return $this->reflectionProvider->hasConstant($nameNode, $namespaceAnswerer); |
| 116: | } |
| 117: | |
| 118: | |
| 119: | |
| 120: | |
| 121: | public function getConstant(Node\Name $nameNode, ?NamespaceAnswerer $namespaceAnswerer): GlobalConstantReflection |
| 122: | { |
| 123: | return $this->reflectionProvider->getConstant($nameNode, $namespaceAnswerer); |
| 124: | } |
| 125: | |
| 126: | |
| 127: | |
| 128: | |
| 129: | public function resolveConstantName(Node\Name $nameNode, ?NamespaceAnswerer $namespaceAnswerer): ?string |
| 130: | { |
| 131: | return $this->reflectionProvider->resolveConstantName($nameNode, $namespaceAnswerer); |
| 132: | } |
| 133: | |
| 134: | |
| 135: | |
| 136: | |
| 137: | |
| 138: | |
| 139: | public function getUniversalObjectCratesClasses(): array |
| 140: | { |
| 141: | return $this->universalObjectCratesClasses; |
| 142: | } |
| 143: | |
| 144: | } |
| 145: | |