Property.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php declare(strict_types=1);
  2. namespace PhpParser\Node\Stmt;
  3. use PhpParser\Node;
  4. use PhpParser\Node\Identifier;
  5. use PhpParser\Node\Name;
  6. use PhpParser\Node\NullableType;
  7. class Property extends Node\Stmt
  8. {
  9. /** @var int Modifiers */
  10. public $flags;
  11. /** @var PropertyProperty[] Properties */
  12. public $props;
  13. /** @var null|Identifier|Name|NullableType Type declaration */
  14. public $type;
  15. /**
  16. * Constructs a class property list node.
  17. *
  18. * @param int $flags Modifiers
  19. * @param PropertyProperty[] $props Properties
  20. * @param array $attributes Additional attributes
  21. * @param null|string|Identifier|Name|NullableType $type Type declaration
  22. */
  23. public function __construct(int $flags, array $props, array $attributes = [], $type = null) {
  24. parent::__construct($attributes);
  25. $this->flags = $flags;
  26. $this->props = $props;
  27. $this->type = \is_string($type) ? new Identifier($type) : $type;
  28. }
  29. public function getSubNodeNames() : array {
  30. return ['flags', 'type', 'props'];
  31. }
  32. /**
  33. * Whether the property is explicitly or implicitly public.
  34. *
  35. * @return bool
  36. */
  37. public function isPublic() : bool {
  38. return ($this->flags & Class_::MODIFIER_PUBLIC) !== 0
  39. || ($this->flags & Class_::VISIBILITY_MODIFIER_MASK) === 0;
  40. }
  41. /**
  42. * Whether the property is protected.
  43. *
  44. * @return bool
  45. */
  46. public function isProtected() : bool {
  47. return (bool) ($this->flags & Class_::MODIFIER_PROTECTED);
  48. }
  49. /**
  50. * Whether the property is private.
  51. *
  52. * @return bool
  53. */
  54. public function isPrivate() : bool {
  55. return (bool) ($this->flags & Class_::MODIFIER_PRIVATE);
  56. }
  57. /**
  58. * Whether the property is static.
  59. *
  60. * @return bool
  61. */
  62. public function isStatic() : bool {
  63. return (bool) ($this->flags & Class_::MODIFIER_STATIC);
  64. }
  65. public function getType() : string {
  66. return 'Stmt_Property';
  67. }
  68. }