1: <?php declare(strict_types=1);
2:
3: namespace PhpParser\Node;
4:
5: use PhpParser\Modifiers;
6: use PhpParser\Node;
7: use PhpParser\NodeAbstract;
8:
9: class Param extends NodeAbstract {
10: /** @var null|Identifier|Name|ComplexType Type declaration */
11: public ?Node $type;
12: /** @var bool Whether parameter is passed by reference */
13: public bool $byRef;
14: /** @var bool Whether this is a variadic argument */
15: public bool $variadic;
16: /** @var Expr\Variable|Expr\Error Parameter variable */
17: public Expr $var;
18: /** @var null|Expr Default value */
19: public ?Expr $default;
20: /** @var int Optional visibility flags */
21: public int $flags;
22: /** @var AttributeGroup[] PHP attribute groups */
23: public array $attrGroups;
24: /** @var PropertyHook[] Property hooks for promoted properties */
25: public array $hooks;
26:
27: /**
28: * Constructs a parameter node.
29: *
30: * @param Expr\Variable|Expr\Error $var Parameter variable
31: * @param null|Expr $default Default value
32: * @param null|Identifier|Name|ComplexType $type Type declaration
33: * @param bool $byRef Whether is passed by reference
34: * @param bool $variadic Whether this is a variadic argument
35: * @param array<string, mixed> $attributes Additional attributes
36: * @param int $flags Optional visibility flags
37: * @param list<AttributeGroup> $attrGroups PHP attribute groups
38: * @param PropertyHook[] $hooks Property hooks for promoted properties
39: */
40: public function __construct(
41: Expr $var, ?Expr $default = null, ?Node $type = null,
42: bool $byRef = false, bool $variadic = false,
43: array $attributes = [],
44: int $flags = 0,
45: array $attrGroups = [],
46: array $hooks = []
47: ) {
48: $this->attributes = $attributes;
49: $this->type = $type;
50: $this->byRef = $byRef;
51: $this->variadic = $variadic;
52: $this->var = $var;
53: $this->default = $default;
54: $this->flags = $flags;
55: $this->attrGroups = $attrGroups;
56: $this->hooks = $hooks;
57: }
58:
59: public function getSubNodeNames(): array {
60: return ['attrGroups', 'flags', 'type', 'byRef', 'variadic', 'var', 'default', 'hooks'];
61: }
62:
63: public function getType(): string {
64: return 'Param';
65: }
66:
67: /**
68: * Whether this parameter uses constructor property promotion.
69: */
70: public function isPromoted(): bool {
71: return $this->flags !== 0;
72: }
73:
74: public function isPublic(): bool {
75: return (bool) ($this->flags & Modifiers::PUBLIC);
76: }
77:
78: public function isProtected(): bool {
79: return (bool) ($this->flags & Modifiers::PROTECTED);
80: }
81:
82: public function isPrivate(): bool {
83: return (bool) ($this->flags & Modifiers::PRIVATE);
84: }
85:
86: public function isReadonly(): bool {
87: return (bool) ($this->flags & Modifiers::READONLY);
88: }
89:
90: /**
91: * Whether the promoted property has explicit public(set) visibility.
92: */
93: public function isPublicSet(): bool {
94: return (bool) ($this->flags & Modifiers::PUBLIC_SET);
95: }
96:
97: /**
98: * Whether the promoted property has explicit protected(set) visibility.
99: */
100: public function isProtectedSet(): bool {
101: return (bool) ($this->flags & Modifiers::PROTECTED_SET);
102: }
103:
104: /**
105: * Whether the promoted property has explicit private(set) visibility.
106: */
107: public function isPrivateSet(): bool {
108: return (bool) ($this->flags & Modifiers::PRIVATE_SET);
109: }
110: }
111: