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