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: * @api
14: */
15: final class ClassPropertyNode extends NodeAbstract implements VirtualNode
16: {
17:
18: public function __construct(
19: private string $name,
20: private int $flags,
21: private ?Type $type,
22: private ?Expr $default,
23: private ?string $phpDoc,
24: private ?Type $phpDocType,
25: private bool $isPromoted,
26: private bool $isPromotedFromTrait,
27: private Node\Stmt\Property|Node\Param $originalNode,
28: private bool $isReadonlyByPhpDoc,
29: private bool $isDeclaredInTrait,
30: private bool $isReadonlyClass,
31: private bool $isAllowedPrivateMutation,
32: private ClassReflection $classReflection,
33: )
34: {
35: parent::__construct($originalNode->getAttributes());
36: }
37:
38: public function getName(): string
39: {
40: return $this->name;
41: }
42:
43: public function getFlags(): int
44: {
45: return $this->flags;
46: }
47:
48: public function getDefault(): ?Expr
49: {
50: return $this->default;
51: }
52:
53: public function isPromoted(): bool
54: {
55: return $this->isPromoted;
56: }
57:
58: public function isPromotedFromTrait(): bool
59: {
60: return $this->isPromotedFromTrait;
61: }
62:
63: public function getPhpDoc(): ?string
64: {
65: return $this->phpDoc;
66: }
67:
68: public function getPhpDocType(): ?Type
69: {
70: return $this->phpDocType;
71: }
72:
73: public function isPublic(): bool
74: {
75: return ($this->flags & Modifiers::PUBLIC) !== 0
76: || ($this->flags & Modifiers::VISIBILITY_MASK) === 0;
77: }
78:
79: public function isProtected(): bool
80: {
81: return (bool) ($this->flags & Modifiers::PROTECTED);
82: }
83:
84: public function isPrivate(): bool
85: {
86: return (bool) ($this->flags & Modifiers::PRIVATE);
87: }
88:
89: public function isStatic(): bool
90: {
91: return (bool) ($this->flags & Modifiers::STATIC);
92: }
93:
94: public function isReadOnly(): bool
95: {
96: return (bool) ($this->flags & Modifiers::READONLY) || $this->isReadonlyClass;
97: }
98:
99: public function isReadOnlyByPhpDoc(): bool
100: {
101: return $this->isReadonlyByPhpDoc;
102: }
103:
104: public function isDeclaredInTrait(): bool
105: {
106: return $this->isDeclaredInTrait;
107: }
108:
109: public function isAllowedPrivateMutation(): bool
110: {
111: return $this->isAllowedPrivateMutation;
112: }
113:
114: public function getNativeType(): ?Type
115: {
116: return $this->type;
117: }
118:
119: /**
120: * @return Node\Identifier|Node\Name|Node\ComplexType|null
121: */
122: public function getNativeTypeNode()
123: {
124: return $this->originalNode->type;
125: }
126:
127: public function getClassReflection(): ClassReflection
128: {
129: return $this->classReflection;
130: }
131:
132: public function getType(): string
133: {
134: return 'PHPStan_Node_ClassPropertyNode';
135: }
136:
137: /**
138: * @return string[]
139: */
140: public function getSubNodeNames(): array
141: {
142: return [];
143: }
144:
145: }
146: