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 22 /** 23 * Constructs a class property list node. 24 * 25 * @param int $flags Modifiers 26 * @param PropertyItem[] $props Properties 27 * @param array<string, mixed> $attributes Additional attributes 28 * @param null|Identifier|Name|ComplexType $type Type declaration 29 * @param Node\AttributeGroup[] $attrGroups PHP attribute groups 30 */ 31 public function __construct(int $flags, array $props, array $attributes = [], ?Node $type = null, array $attrGroups = []) { 32 $this->attributes = $attributes; 33 $this->flags = $flags; 34 $this->props = $props; 35 $this->type = $type; 36 $this->attrGroups = $attrGroups; 37 } 38 39 public function getSubNodeNames(): array { 40 return ['attrGroups', 'flags', 'type', 'props']; 41 } 42 43 /** 44 * Whether the property is explicitly or implicitly public. 45 */ 46 public function isPublic(): bool { 47 return ($this->flags & Modifiers::PUBLIC) !== 0 48 || ($this->flags & Modifiers::VISIBILITY_MASK) === 0; 49 } 50 51 /** 52 * Whether the property is protected. 53 */ 54 public function isProtected(): bool { 55 return (bool) ($this->flags & Modifiers::PROTECTED); 56 } 57 58 /** 59 * Whether the property is private. 60 */ 61 public function isPrivate(): bool { 62 return (bool) ($this->flags & Modifiers::PRIVATE); 63 } 64 65 /** 66 * Whether the property is static. 67 */ 68 public function isStatic(): bool { 69 return (bool) ($this->flags & Modifiers::STATIC); 70 } 71 72 /** 73 * Whether the property is readonly. 74 */ 75 public function isReadonly(): bool { 76 return (bool) ($this->flags & Modifiers::READONLY); 77 } 78 79 public function getType(): string { 80 return 'Stmt_Property'; 81 } 82} 83