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