| 1: | <?php declare(strict_types = 1); |
| 2: | |
| 3: | namespace PHPStan\Node; |
| 4: | |
| 5: | use Override; |
| 6: | use PhpParser\Modifiers; |
| 7: | use PhpParser\Node; |
| 8: | use PhpParser\Node\Expr; |
| 9: | use PhpParser\NodeAbstract; |
| 10: | use PHPStan\Reflection\ClassReflection; |
| 11: | use PHPStan\Type\Type; |
| 12: | |
| 13: | |
| 14: | |
| 15: | |
| 16: | final class ClassPropertyNode extends NodeAbstract implements VirtualNode |
| 17: | { |
| 18: | |
| 19: | |
| 20: | |
| 21: | |
| 22: | public function __construct( |
| 23: | private string $name, |
| 24: | private int $flags, |
| 25: | private ?Type $type, |
| 26: | private ?Expr $default, |
| 27: | private ?string $phpDoc, |
| 28: | private ?Type $phpDocType, |
| 29: | private bool $isPromoted, |
| 30: | private bool $isPromotedFromTrait, |
| 31: | private Node\Stmt\Property|Node\Param $originalNode, |
| 32: | private bool $isReadonlyByPhpDoc, |
| 33: | private bool $isDeclaredInTrait, |
| 34: | private bool $isReadonlyClass, |
| 35: | private bool $isAllowedPrivateMutation, |
| 36: | private ClassReflection $classReflection, |
| 37: | ) |
| 38: | { |
| 39: | parent::__construct($originalNode->getAttributes()); |
| 40: | } |
| 41: | |
| 42: | |
| 43: | public function getName(): string |
| 44: | { |
| 45: | return $this->name; |
| 46: | } |
| 47: | |
| 48: | public function getFlags(): int |
| 49: | { |
| 50: | return $this->flags; |
| 51: | } |
| 52: | |
| 53: | public function getDefault(): ?Expr |
| 54: | { |
| 55: | return $this->default; |
| 56: | } |
| 57: | |
| 58: | public function isPromoted(): bool |
| 59: | { |
| 60: | return $this->isPromoted; |
| 61: | } |
| 62: | |
| 63: | public function isPromotedFromTrait(): bool |
| 64: | { |
| 65: | return $this->isPromotedFromTrait; |
| 66: | } |
| 67: | |
| 68: | public function getOriginalNode(): Node\Stmt\Property|Node\Param |
| 69: | { |
| 70: | return $this->originalNode; |
| 71: | } |
| 72: | |
| 73: | public function getPhpDoc(): ?string |
| 74: | { |
| 75: | return $this->phpDoc; |
| 76: | } |
| 77: | |
| 78: | public function getPhpDocType(): ?Type |
| 79: | { |
| 80: | return $this->phpDocType; |
| 81: | } |
| 82: | |
| 83: | public function isPublic(): bool |
| 84: | { |
| 85: | return ($this->flags & Modifiers::PUBLIC) !== 0 |
| 86: | || ($this->flags & Modifiers::VISIBILITY_MASK) === 0; |
| 87: | } |
| 88: | |
| 89: | public function isProtected(): bool |
| 90: | { |
| 91: | return (bool) ($this->flags & Modifiers::PROTECTED); |
| 92: | } |
| 93: | |
| 94: | public function isPrivate(): bool |
| 95: | { |
| 96: | return (bool) ($this->flags & Modifiers::PRIVATE); |
| 97: | } |
| 98: | |
| 99: | public function isPrivateSet(): bool |
| 100: | { |
| 101: | return (bool) ($this->flags & Modifiers::PRIVATE_SET); |
| 102: | } |
| 103: | |
| 104: | public function isProtectedSet(): bool |
| 105: | { |
| 106: | return (bool) ($this->flags & Modifiers::PROTECTED_SET); |
| 107: | } |
| 108: | |
| 109: | public function isPublicSet(): bool |
| 110: | { |
| 111: | return (bool) ($this->flags & Modifiers::PUBLIC_SET); |
| 112: | } |
| 113: | |
| 114: | public function isFinal(): bool |
| 115: | { |
| 116: | return (bool) ($this->flags & Modifiers::FINAL); |
| 117: | } |
| 118: | |
| 119: | public function isStatic(): bool |
| 120: | { |
| 121: | return (bool) ($this->flags & Modifiers::STATIC); |
| 122: | } |
| 123: | |
| 124: | public function isReadOnly(): bool |
| 125: | { |
| 126: | return (bool) ($this->flags & Modifiers::READONLY) || $this->isReadonlyClass; |
| 127: | } |
| 128: | |
| 129: | public function isReadOnlyByPhpDoc(): bool |
| 130: | { |
| 131: | return $this->isReadonlyByPhpDoc; |
| 132: | } |
| 133: | |
| 134: | public function isDeclaredInTrait(): bool |
| 135: | { |
| 136: | return $this->isDeclaredInTrait; |
| 137: | } |
| 138: | |
| 139: | public function isAllowedPrivateMutation(): bool |
| 140: | { |
| 141: | return $this->isAllowedPrivateMutation; |
| 142: | } |
| 143: | |
| 144: | public function isAbstract(): bool |
| 145: | { |
| 146: | return (bool) ($this->flags & Modifiers::ABSTRACT); |
| 147: | } |
| 148: | |
| 149: | public function getNativeType(): ?Type |
| 150: | { |
| 151: | return $this->type; |
| 152: | } |
| 153: | |
| 154: | |
| 155: | |
| 156: | |
| 157: | public function getNativeTypeNode() |
| 158: | { |
| 159: | return $this->originalNode->type; |
| 160: | } |
| 161: | |
| 162: | public function getClassReflection(): ClassReflection |
| 163: | { |
| 164: | return $this->classReflection; |
| 165: | } |
| 166: | |
| 167: | #[Override] |
| 168: | public function getType(): string |
| 169: | { |
| 170: | return 'PHPStan_Node_ClassPropertyNode'; |
| 171: | } |
| 172: | |
| 173: | |
| 174: | |
| 175: | |
| 176: | #[Override] |
| 177: | public function getSubNodeNames(): array |
| 178: | { |
| 179: | return []; |
| 180: | } |
| 181: | |
| 182: | public function hasHooks(): bool |
| 183: | { |
| 184: | return $this->getHooks() !== []; |
| 185: | } |
| 186: | |
| 187: | |
| 188: | |
| 189: | |
| 190: | public function getHooks(): array |
| 191: | { |
| 192: | return $this->originalNode->hooks; |
| 193: | } |
| 194: | |
| 195: | public function isVirtual(): bool |
| 196: | { |
| 197: | return $this->classReflection->getNativeProperty($this->name)->isVirtual()->yes(); |
| 198: | } |
| 199: | |
| 200: | public function isWritable(): bool |
| 201: | { |
| 202: | return $this->classReflection->getNativeProperty($this->name)->isWritable(); |
| 203: | } |
| 204: | |
| 205: | public function isReadable(): bool |
| 206: | { |
| 207: | return $this->classReflection->getNativeProperty($this->name)->isReadable(); |
| 208: | } |
| 209: | |
| 210: | |
| 211: | |
| 212: | |
| 213: | public function getAttrGroups(): array |
| 214: | { |
| 215: | return $this->originalNode->attrGroups; |
| 216: | } |
| 217: | |
| 218: | } |
| 219: | |