|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace ArchTech\Enums\PHPStan\InvokableCases; |
| 6 | + |
| 7 | +use PHPStan\Analyser\OutOfClassScope; |
| 8 | +use PHPStan\Reflection\ClassMemberReflection; |
| 9 | +use PHPStan\Reflection\ClassReflection; |
| 10 | +use PHPStan\Reflection\FunctionVariant; |
| 11 | +use PHPStan\Reflection\MethodReflection; |
| 12 | +use PHPStan\Reflection\ParametersAcceptor; |
| 13 | +use PHPStan\TrinaryLogic; |
| 14 | +use PHPStan\Type\Generic\TemplateTypeMap; |
| 15 | +use PHPStan\Type\StringType; |
| 16 | +use PHPStan\Type\Type; |
| 17 | + |
| 18 | +class StaticInvokableCaseMethodReflection implements MethodReflection |
| 19 | +{ |
| 20 | + private readonly MethodReflection $callStaticMethod; |
| 21 | + |
| 22 | + public function __construct( |
| 23 | + private readonly ClassReflection $classReflection, |
| 24 | + private readonly string $name, |
| 25 | + ) { |
| 26 | + $this->callStaticMethod = $this->classReflection->getMethod('__callStatic', new OutOfClassScope()); |
| 27 | + } |
| 28 | + |
| 29 | + public function getDeclaringClass(): ClassReflection |
| 30 | + { |
| 31 | + return $this->classReflection; |
| 32 | + } |
| 33 | + |
| 34 | + public function isStatic(): bool |
| 35 | + { |
| 36 | + return true; |
| 37 | + } |
| 38 | + |
| 39 | + public function isPrivate(): bool |
| 40 | + { |
| 41 | + return false; |
| 42 | + } |
| 43 | + |
| 44 | + public function isPublic(): bool |
| 45 | + { |
| 46 | + return true; |
| 47 | + } |
| 48 | + |
| 49 | + public function getDocComment(): ?string |
| 50 | + { |
| 51 | + return $this->callStaticMethod->getDocComment(); |
| 52 | + } |
| 53 | + |
| 54 | + public function getName(): string |
| 55 | + { |
| 56 | + return $this->name; |
| 57 | + } |
| 58 | + |
| 59 | + public function getPrototype(): ClassMemberReflection |
| 60 | + { |
| 61 | + return $this; |
| 62 | + } |
| 63 | + |
| 64 | + /** |
| 65 | + * @return ParametersAcceptor[] |
| 66 | + */ |
| 67 | + public function getVariants(): array |
| 68 | + { |
| 69 | + return [ |
| 70 | + new FunctionVariant( |
| 71 | + TemplateTypeMap::createEmpty(), |
| 72 | + TemplateTypeMap::createEmpty(), |
| 73 | + [], |
| 74 | + false, |
| 75 | + $this->classReflection->getBackedEnumType() ?? new StringType() |
| 76 | + ), |
| 77 | + ]; |
| 78 | + } |
| 79 | + |
| 80 | + public function isDeprecated(): TrinaryLogic |
| 81 | + { |
| 82 | + return $this->callStaticMethod->isDeprecated(); |
| 83 | + } |
| 84 | + |
| 85 | + public function getDeprecatedDescription(): ?string |
| 86 | + { |
| 87 | + return $this->callStaticMethod->getDeprecatedDescription(); |
| 88 | + } |
| 89 | + |
| 90 | + public function isFinal(): TrinaryLogic |
| 91 | + { |
| 92 | + return TrinaryLogic::createNo(); |
| 93 | + } |
| 94 | + |
| 95 | + public function isInternal(): TrinaryLogic |
| 96 | + { |
| 97 | + return TrinaryLogic::createNo(); |
| 98 | + } |
| 99 | + |
| 100 | + public function getThrowType(): ?Type |
| 101 | + { |
| 102 | + return $this->callStaticMethod->getThrowType(); |
| 103 | + } |
| 104 | + |
| 105 | + public function hasSideEffects(): TrinaryLogic |
| 106 | + { |
| 107 | + return TrinaryLogic::createNo(); |
| 108 | + } |
| 109 | +} |
0 commit comments