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: /** @api */
15: class ClassPropertyNode extends NodeAbstract implements VirtualNode
16: {
17:
18: public function __construct(
19: private string $name,
20: private int $flags,
21: private Identifier|Name|Node\ComplexType|null $type,
22: private ?Expr $default,
23: private ?string $phpDoc,
24: private ?Type $phpDocType,
25: private bool $isPromoted,
26: private bool $isPromotedFromTrait,
27: Node $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 & Class_::MODIFIER_PUBLIC) !== 0
76: || ($this->flags & Class_::VISIBILITY_MODIFIER_MASK) === 0;
77: }
78:
79: public function isProtected(): bool
80: {
81: return (bool) ($this->flags & Class_::MODIFIER_PROTECTED);
82: }
83:
84: public function isPrivate(): bool
85: {
86: return (bool) ($this->flags & Class_::MODIFIER_PRIVATE);
87: }
88:
89: public function isStatic(): bool
90: {
91: return (bool) ($this->flags & Class_::MODIFIER_STATIC);
92: }
93:
94: public function isReadOnly(): bool
95: {
96: return (bool) ($this->flags & Class_::MODIFIER_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: /**
115: * @return Identifier|Name|Node\ComplexType|null
116: */
117: public function getNativeType()
118: {
119: return $this->type;
120: }
121:
122: public function getClassReflection(): ClassReflection
123: {
124: return $this->classReflection;
125: }
126:
127: public function getType(): string
128: {
129: return 'PHPStan_Node_ClassPropertyNode';
130: }
131:
132: /**
133: * @return string[]
134: */
135: public function getSubNodeNames(): array
136: {
137: return [];
138: }
139:
140: }
141: