1<?php declare(strict_types=1); 2 3namespace PhpParser\Node\Stmt; 4 5use PhpParser\Modifiers; 6use PhpParser\Node; 7use PhpParser\Node\ComplexType; 8use PhpParser\Node\Identifier; 9use PhpParser\Node\Name; 10use PhpParser\Node\PropertyItem; 11 12class Property extends Node\Stmt { 13 /** @var int Modifiers */ 14 public int $flags; 15 /** @var PropertyItem[] Properties */ 16 public array $props; 17 /** @var null|Identifier|Name|ComplexType Type declaration */ 18 public ?Node $type; 19 /** @var Node\AttributeGroup[] PHP attribute groups */ 20 public array $attrGroups; 21 /** @var Node\PropertyHook[] Property hooks */ 22 public array $hooks; 23 24 /** 25 * Constructs a class property list node. 26 * 27 * @param int $flags Modifiers 28 * @param PropertyItem[] $props Properties 29 * @param array<string, mixed> $attributes Additional attributes 30 * @param null|Identifier|Name|ComplexType $type Type declaration 31 * @param Node\AttributeGroup[] $attrGroups PHP attribute groups 32 * @param Node\PropertyHook[] $hooks Property hooks 33 */ 34 public function __construct(int $flags, array $props, array $attributes = [], ?Node $type = null, array $attrGroups = [], array $hooks = []) { 35 $this->attributes = $attributes; 36 $this->flags = $flags; 37 $this->props = $props; 38 $this->type = $type; 39 $this->attrGroups = $attrGroups; 40 $this->hooks = $hooks; 41 } 42 43 public function getSubNodeNames(): array { 44 return ['attrGroups', 'flags', 'type', 'props', 'hooks']; 45 } 46 47 /** 48 * Whether the property is explicitly or implicitly public. 49 */ 50 public function isPublic(): bool { 51 return ($this->flags & Modifiers::PUBLIC) !== 0 52 || ($this->flags & Modifiers::VISIBILITY_MASK) === 0; 53 } 54 55 /** 56 * Whether the property is protected. 57 */ 58 public function isProtected(): bool { 59 return (bool) ($this->flags & Modifiers::PROTECTED); 60 } 61 62 /** 63 * Whether the property is private. 64 */ 65 public function isPrivate(): bool { 66 return (bool) ($this->flags & Modifiers::PRIVATE); 67 } 68 69 /** 70 * Whether the property is static. 71 */ 72 public function isStatic(): bool { 73 return (bool) ($this->flags & Modifiers::STATIC); 74 } 75 76 /** 77 * Whether the property is readonly. 78 */ 79 public function isReadonly(): bool { 80 return (bool) ($this->flags & Modifiers::READONLY); 81 } 82 83 /** 84 * Whether the property has explicit public(set) visibility. 85 */ 86 public function isPublicSet(): bool { 87 return (bool) ($this->flags & Modifiers::PUBLIC_SET); 88 } 89 90 /** 91 * Whether the property has explicit protected(set) visibility. 92 */ 93 public function isProtectedSet(): bool { 94 return (bool) ($this->flags & Modifiers::PROTECTED_SET); 95 } 96 97 /** 98 * Whether the property has explicit private(set) visibility. 99 */ 100 public function isPrivateSet(): bool { 101 return (bool) ($this->flags & Modifiers::PRIVATE_SET); 102 } 103 104 public function getType(): string { 105 return 'Stmt_Property'; 106 } 107} 108