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