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:
12: /** @api */
13: class ClassPropertyNode extends NodeAbstract implements VirtualNode
14: {
15:
16: public function __construct(
17: private string $name,
18: private int $flags,
19: private Identifier|Name|Node\ComplexType|null $type,
20: private ?Expr $default,
21: private ?string $phpDoc,
22: private bool $isPromoted,
23: Node $originalNode,
24: private bool $isReadonlyByPhpDoc,
25: private bool $isDeclaredInTrait,
26: private bool $isReadonlyClass,
27: )
28: {
29: parent::__construct($originalNode->getAttributes());
30: }
31:
32: public function getName(): string
33: {
34: return $this->name;
35: }
36:
37: public function getFlags(): int
38: {
39: return $this->flags;
40: }
41:
42: public function getDefault(): ?Expr
43: {
44: return $this->default;
45: }
46:
47: public function isPromoted(): bool
48: {
49: return $this->isPromoted;
50: }
51:
52: public function getPhpDoc(): ?string
53: {
54: return $this->phpDoc;
55: }
56:
57: public function isPublic(): bool
58: {
59: return ($this->flags & Class_::MODIFIER_PUBLIC) !== 0
60: || ($this->flags & Class_::VISIBILITY_MODIFIER_MASK) === 0;
61: }
62:
63: public function isProtected(): bool
64: {
65: return (bool) ($this->flags & Class_::MODIFIER_PROTECTED);
66: }
67:
68: public function isPrivate(): bool
69: {
70: return (bool) ($this->flags & Class_::MODIFIER_PRIVATE);
71: }
72:
73: public function isStatic(): bool
74: {
75: return (bool) ($this->flags & Class_::MODIFIER_STATIC);
76: }
77:
78: public function isReadOnly(): bool
79: {
80: return (bool) ($this->flags & Class_::MODIFIER_READONLY) || $this->isReadonlyClass;
81: }
82:
83: public function isReadOnlyByPhpDoc(): bool
84: {
85: return $this->isReadonlyByPhpDoc;
86: }
87:
88: public function isDeclaredInTrait(): bool
89: {
90: return $this->isDeclaredInTrait;
91: }
92:
93: /**
94: * @return Identifier|Name|Node\ComplexType|null
95: */
96: public function getNativeType()
97: {
98: return $this->type;
99: }
100:
101: public function getType(): string
102: {
103: return 'PHPStan_Node_ClassPropertyNode';
104: }
105:
106: /**
107: * @return string[]
108: */
109: public function getSubNodeNames(): array
110: {
111: return [];
112: }
113:
114: }
115: