Param.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php declare(strict_types=1);
  2. namespace PhpParser\Node;
  3. use PhpParser\Modifiers;
  4. use PhpParser\Node;
  5. use PhpParser\NodeAbstract;
  6. class Param extends NodeAbstract {
  7. /** @var null|Identifier|Name|ComplexType Type declaration */
  8. public ?Node $type;
  9. /** @var bool Whether parameter is passed by reference */
  10. public bool $byRef;
  11. /** @var bool Whether this is a variadic argument */
  12. public bool $variadic;
  13. /** @var Expr\Variable|Expr\Error Parameter variable */
  14. public Expr $var;
  15. /** @var null|Expr Default value */
  16. public ?Expr $default;
  17. /** @var int Optional visibility flags */
  18. public int $flags;
  19. /** @var AttributeGroup[] PHP attribute groups */
  20. public array $attrGroups;
  21. /**
  22. * Constructs a parameter node.
  23. *
  24. * @param Expr\Variable|Expr\Error $var Parameter variable
  25. * @param null|Expr $default Default value
  26. * @param null|Identifier|Name|ComplexType $type Type declaration
  27. * @param bool $byRef Whether is passed by reference
  28. * @param bool $variadic Whether this is a variadic argument
  29. * @param array<string, mixed> $attributes Additional attributes
  30. * @param int $flags Optional visibility flags
  31. * @param list<AttributeGroup> $attrGroups PHP attribute groups
  32. */
  33. public function __construct(
  34. Expr $var, ?Expr $default = null, ?Node $type = null,
  35. bool $byRef = false, bool $variadic = false,
  36. array $attributes = [],
  37. int $flags = 0,
  38. array $attrGroups = []
  39. ) {
  40. $this->attributes = $attributes;
  41. $this->type = $type;
  42. $this->byRef = $byRef;
  43. $this->variadic = $variadic;
  44. $this->var = $var;
  45. $this->default = $default;
  46. $this->flags = $flags;
  47. $this->attrGroups = $attrGroups;
  48. }
  49. public function getSubNodeNames(): array {
  50. return ['attrGroups', 'flags', 'type', 'byRef', 'variadic', 'var', 'default'];
  51. }
  52. public function getType(): string {
  53. return 'Param';
  54. }
  55. /**
  56. * Whether this parameter uses constructor property promotion.
  57. */
  58. public function isPromoted(): bool {
  59. return $this->flags !== 0;
  60. }
  61. public function isPublic(): bool {
  62. return (bool) ($this->flags & Modifiers::PUBLIC);
  63. }
  64. public function isProtected(): bool {
  65. return (bool) ($this->flags & Modifiers::PROTECTED);
  66. }
  67. public function isPrivate(): bool {
  68. return (bool) ($this->flags & Modifiers::PRIVATE);
  69. }
  70. public function isReadonly(): bool {
  71. return (bool) ($this->flags & Modifiers::READONLY);
  72. }
  73. }