| 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 || $this->hooks !== []; |
| 72 |
} |
| 73 |
|
| 74 |
public function isFinal(): bool { |
| 75 |
return (bool) ($this->flags & Modifiers::FINAL); |
| 76 |
} |
| 77 |
|
| 78 |
public function isPublic(): bool { |
| 79 |
$public = (bool) ($this->flags & Modifiers::PUBLIC); |
| 80 |
if ($public) { |
| 81 |
return true; |
| 82 |
} |
| 83 |
|
| 84 |
if (!$this->isPromoted()) { |
| 85 |
return false; |
| 86 |
} |
| 87 |
|
| 88 |
return ($this->flags & Modifiers::VISIBILITY_MASK) === 0; |
| 89 |
} |
| 90 |
|
| 91 |
public function isProtected(): bool { |
| 92 |
return (bool) ($this->flags & Modifiers::PROTECTED); |
| 93 |
} |
| 94 |
|
| 95 |
public function isPrivate(): bool { |
| 96 |
return (bool) ($this->flags & Modifiers::PRIVATE); |
| 97 |
} |
| 98 |
|
| 99 |
public function isReadonly(): bool { |
| 100 |
return (bool) ($this->flags & Modifiers::READONLY); |
| 101 |
} |
| 102 |
|
| 103 |
/** |
| 104 |
* Whether the promoted property has explicit public(set) visibility. |
| 105 |
*/ |
| 106 |
public function isPublicSet(): bool { |
| 107 |
return (bool) ($this->flags & Modifiers::PUBLIC_SET); |
| 108 |
} |
| 109 |
|
| 110 |
/** |
| 111 |
* Whether the promoted property has explicit protected(set) visibility. |
| 112 |
*/ |
| 113 |
public function isProtectedSet(): bool { |
| 114 |
return (bool) ($this->flags & Modifiers::PROTECTED_SET); |
| 115 |
} |
| 116 |
|
| 117 |
/** |
| 118 |
* Whether the promoted property has explicit private(set) visibility. |
| 119 |
*/ |
| 120 |
public function isPrivateSet(): bool { |
| 121 |
return (bool) ($this->flags & Modifiers::PRIVATE_SET); |
| 122 |
} |
| 123 |
} |