| 1 |
<?php |
| 2 |
|
| 3 |
declare(strict_types=1); |
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
namespace Carbon\PHPStan; |
| 15 |
|
| 16 |
use PHPStan\Reflection\ClassReflection; |
| 17 |
use PHPStan\Reflection\MethodReflection; |
| 18 |
use PHPStan\Reflection\ParametersAcceptor; |
| 19 |
use PHPStan\TrinaryLogic; |
| 20 |
use PHPStan\Type\Type; |
| 21 |
|
| 22 |
use function preg_match; |
| 23 |
|
| 24 |
class MacroMethodReflection implements MethodReflection |
| 25 |
{ |
| 26 |
private ClassReflection $declaringClass; |
| 27 |
private string $methodName; |
| 28 |
private ParametersAcceptor $macroClosureType; |
| 29 |
private bool $static; |
| 30 |
private bool $final; |
| 31 |
private bool $deprecated; |
| 32 |
private ?string $docComment; |
| 33 |
|
| 34 |
public function __construct( |
| 35 |
ClassReflection $declaringClass, |
| 36 |
string $methodName, |
| 37 |
ParametersAcceptor $macroClosureType, |
| 38 |
bool $static, |
| 39 |
bool $final, |
| 40 |
bool $deprecated, |
| 41 |
?string $docComment |
| 42 |
) { |
| 43 |
$this->declaringClass = $declaringClass; |
| 44 |
$this->methodName = $methodName; |
| 45 |
$this->macroClosureType = $macroClosureType; |
| 46 |
$this->static = $static; |
| 47 |
$this->final = $final; |
| 48 |
$this->deprecated = $deprecated; |
| 49 |
$this->docComment = $docComment; |
| 50 |
} |
| 51 |
|
| 52 |
public function getDeclaringClass(): ClassReflection |
| 53 |
{ |
| 54 |
return $this->declaringClass; |
| 55 |
} |
| 56 |
|
| 57 |
public function isStatic(): bool |
| 58 |
{ |
| 59 |
return $this->static; |
| 60 |
} |
| 61 |
|
| 62 |
public function isPrivate(): bool |
| 63 |
{ |
| 64 |
return false; |
| 65 |
} |
| 66 |
|
| 67 |
public function isPublic(): bool |
| 68 |
{ |
| 69 |
return true; |
| 70 |
} |
| 71 |
|
| 72 |
public function getDocComment(): ?string |
| 73 |
{ |
| 74 |
return $this->docComment; |
| 75 |
} |
| 76 |
|
| 77 |
public function getName(): string |
| 78 |
{ |
| 79 |
return $this->methodName; |
| 80 |
} |
| 81 |
|
| 82 |
public function getPrototype(): \PHPStan\Reflection\ClassMemberReflection |
| 83 |
{ |
| 84 |
return $this; |
| 85 |
} |
| 86 |
|
| 87 |
public function getVariants(): array |
| 88 |
{ |
| 89 |
return [$this->macroClosureType]; |
| 90 |
} |
| 91 |
|
| 92 |
public function isDeprecated(): TrinaryLogic |
| 93 |
{ |
| 94 |
return TrinaryLogic::createFromBoolean( |
| 95 |
$this->deprecated || |
| 96 |
preg_match('/@deprecated/i', $this->getDocComment() ?: '') |
| 97 |
); |
| 98 |
} |
| 99 |
|
| 100 |
public function getDeprecatedDescription(): ?string |
| 101 |
{ |
| 102 |
return null; |
| 103 |
} |
| 104 |
|
| 105 |
public function isFinal(): TrinaryLogic |
| 106 |
{ |
| 107 |
return TrinaryLogic::createFromBoolean($this->final); |
| 108 |
} |
| 109 |
|
| 110 |
public function isInternal(): TrinaryLogic |
| 111 |
{ |
| 112 |
return TrinaryLogic::createNo(); |
| 113 |
} |
| 114 |
|
| 115 |
public function getThrowType(): ?Type |
| 116 |
{ |
| 117 |
return null; |
| 118 |
} |
| 119 |
|
| 120 |
public function hasSideEffects(): TrinaryLogic |
| 121 |
{ |
| 122 |
return TrinaryLogic::createMaybe(); |
| 123 |
} |
| 124 |
} |