1: <?php declare(strict_types = 1);
2:
3: namespace PHPStan\Node;
4:
5: use PhpParser\Node;
6: use PhpParser\Node\Expr;
7: use PhpParser\Node\Identifier;
8: use PhpParser\Node\Name;
9: use PhpParser\Node\Stmt\Class_;
10: use PhpParser\NodeAbstract;
11: use PHPStan\Reflection\ClassReflection;
12: use PHPStan\Type\Type;
13:
14: /**
15: * @api
16: * @final
17: */
18: class ClassPropertyNode extends NodeAbstract implements VirtualNode
19: {
20:
21: public function __construct(
22: private string $name,
23: private int $flags,
24: private Identifier|Name|Node\ComplexType|null $type,
25: private ?Expr $default,
26: private ?string $phpDoc,
27: private ?Type $phpDocType,
28: private bool $isPromoted,
29: private bool $isPromotedFromTrait,
30: Node $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: public function getName(): string
42: {
43: return $this->name;
44: }
45:
46: public function getFlags(): int
47: {
48: return $this->flags;
49: }
50:
51: public function getDefault(): ?Expr
52: {
53: return $this->default;
54: }
55:
56: public function isPromoted(): bool
57: {
58: return $this->isPromoted;
59: }
60:
61: public function isPromotedFromTrait(): bool
62: {
63: return $this->isPromotedFromTrait;
64: }
65:
66: public function getPhpDoc(): ?string
67: {
68: return $this->phpDoc;
69: }
70:
71: public function getPhpDocType(): ?Type
72: {
73: return $this->phpDocType;
74: }
75:
76: public function isPublic(): bool
77: {
78: return ($this->flags & Class_::MODIFIER_PUBLIC) !== 0
79: || ($this->flags & Class_::VISIBILITY_MODIFIER_MASK) === 0;
80: }
81:
82: public function isProtected(): bool
83: {
84: return (bool) ($this->flags & Class_::MODIFIER_PROTECTED);
85: }
86:
87: public function isPrivate(): bool
88: {
89: return (bool) ($this->flags & Class_::MODIFIER_PRIVATE);
90: }
91:
92: public function isStatic(): bool
93: {
94: return (bool) ($this->flags & Class_::MODIFIER_STATIC);
95: }
96:
97: public function isReadOnly(): bool
98: {
99: return (bool) ($this->flags & Class_::MODIFIER_READONLY) || $this->isReadonlyClass;
100: }
101:
102: public function isReadOnlyByPhpDoc(): bool
103: {
104: return $this->isReadonlyByPhpDoc;
105: }
106:
107: public function isDeclaredInTrait(): bool
108: {
109: return $this->isDeclaredInTrait;
110: }
111:
112: public function isAllowedPrivateMutation(): bool
113: {
114: return $this->isAllowedPrivateMutation;
115: }
116:
117: /**
118: * @return Identifier|Name|Node\ComplexType|null
119: */
120: public function getNativeType()
121: {
122: return $this->type;
123: }
124:
125: public function getClassReflection(): ClassReflection
126: {
127: return $this->classReflection;
128: }
129:
130: public function getType(): string
131: {
132: return 'PHPStan_Node_ClassPropertyNode';
133: }
134:
135: /**
136: * @return string[]
137: */
138: public function getSubNodeNames(): array
139: {
140: return [];
141: }
142:
143: }
144: