ClassConst.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php declare(strict_types=1);
  2. namespace PhpParser\Node\Stmt;
  3. use PhpParser\Node;
  4. class ClassConst extends Node\Stmt
  5. {
  6. /** @var int Modifiers */
  7. public $flags;
  8. /** @var Node\Const_[] Constant declarations */
  9. public $consts;
  10. /** @var Node\AttributeGroup[] PHP attribute groups */
  11. public $attrGroups;
  12. /** @var Node\Identifier|Node\Name|Node\ComplexType|null Type declaration */
  13. public $type;
  14. /**
  15. * Constructs a class const list node.
  16. *
  17. * @param Node\Const_[] $consts Constant declarations
  18. * @param int $flags Modifiers
  19. * @param array $attributes Additional attributes
  20. * @param Node\AttributeGroup[] $attrGroups PHP attribute groups
  21. * @param null|string|Node\Identifier|Node\Name|Node\ComplexType $type Type declaration
  22. */
  23. public function __construct(
  24. array $consts,
  25. int $flags = 0,
  26. array $attributes = [],
  27. array $attrGroups = [],
  28. $type = null
  29. ) {
  30. $this->attributes = $attributes;
  31. $this->flags = $flags;
  32. $this->consts = $consts;
  33. $this->attrGroups = $attrGroups;
  34. $this->type = \is_string($type) ? new Node\Identifier($type) : $type;
  35. }
  36. public function getSubNodeNames() : array {
  37. return ['attrGroups', 'flags', 'type', 'consts'];
  38. }
  39. /**
  40. * Whether constant is explicitly or implicitly public.
  41. *
  42. * @return bool
  43. */
  44. public function isPublic() : bool {
  45. return ($this->flags & Class_::MODIFIER_PUBLIC) !== 0
  46. || ($this->flags & Class_::VISIBILITY_MODIFIER_MASK) === 0;
  47. }
  48. /**
  49. * Whether constant is protected.
  50. *
  51. * @return bool
  52. */
  53. public function isProtected() : bool {
  54. return (bool) ($this->flags & Class_::MODIFIER_PROTECTED);
  55. }
  56. /**
  57. * Whether constant is private.
  58. *
  59. * @return bool
  60. */
  61. public function isPrivate() : bool {
  62. return (bool) ($this->flags & Class_::MODIFIER_PRIVATE);
  63. }
  64. /**
  65. * Whether constant is final.
  66. *
  67. * @return bool
  68. */
  69. public function isFinal() : bool {
  70. return (bool) ($this->flags & Class_::MODIFIER_FINAL);
  71. }
  72. public function getType() : string {
  73. return 'Stmt_ClassConst';
  74. }
  75. }