ClassConst.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php declare(strict_types=1);
  2. namespace PhpParser\Node\Stmt;
  3. use PhpParser\Modifiers;
  4. use PhpParser\Node;
  5. class ClassConst extends Node\Stmt {
  6. /** @var int Modifiers */
  7. public int $flags;
  8. /** @var Node\Const_[] Constant declarations */
  9. public array $consts;
  10. /** @var Node\AttributeGroup[] PHP attribute groups */
  11. public array $attrGroups;
  12. /** @var Node\Identifier|Node\Name|Node\ComplexType|null Type declaration */
  13. public ?Node $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<string, mixed> $attributes Additional attributes
  20. * @param list<Node\AttributeGroup> $attrGroups PHP attribute groups
  21. * @param null|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. ?Node $type = null
  29. ) {
  30. $this->attributes = $attributes;
  31. $this->flags = $flags;
  32. $this->consts = $consts;
  33. $this->attrGroups = $attrGroups;
  34. $this->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. public function isPublic(): bool {
  43. return ($this->flags & Modifiers::PUBLIC) !== 0
  44. || ($this->flags & Modifiers::VISIBILITY_MASK) === 0;
  45. }
  46. /**
  47. * Whether constant is protected.
  48. */
  49. public function isProtected(): bool {
  50. return (bool) ($this->flags & Modifiers::PROTECTED);
  51. }
  52. /**
  53. * Whether constant is private.
  54. */
  55. public function isPrivate(): bool {
  56. return (bool) ($this->flags & Modifiers::PRIVATE);
  57. }
  58. /**
  59. * Whether constant is final.
  60. */
  61. public function isFinal(): bool {
  62. return (bool) ($this->flags & Modifiers::FINAL);
  63. }
  64. public function getType(): string {
  65. return 'Stmt_ClassConst';
  66. }
  67. }