Make NullsafeMethodCall extend from CallLike

This commit is contained in:
Nikita Popov 2021-11-14 17:43:29 +01:00
parent 6f1f206862
commit 4122ff3a91
2 changed files with 27 additions and 7 deletions

View File

@ -5,23 +5,24 @@ namespace PhpParser\Node\Expr;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr;
use PhpParser\Node\Identifier;
use PhpParser\Node\VariadicPlaceholder;
class NullsafeMethodCall extends Expr
class NullsafeMethodCall extends CallLike
{
/** @var Expr Variable holding object */
public $var;
/** @var Identifier|Expr Method name */
public $name;
/** @var Arg[] Arguments */
/** @var array<Arg|VariadicPlaceholder> Arguments */
public $args;
/**
* Constructs a nullsafe method call node.
*
* @param Expr $var Variable holding object
* @param string|Identifier|Expr $name Method name
* @param Arg[] $args Arguments
* @param array $attributes Additional attributes
* @param Expr $var Variable holding object
* @param string|Identifier|Expr $name Method name
* @param array<Arg|VariadicPlaceholder> $args Arguments
* @param array $attributes Additional attributes
*/
public function __construct(Expr $var, $name, array $args = [], array $attributes = []) {
$this->attributes = $attributes;
@ -37,4 +38,8 @@ class NullsafeMethodCall extends Expr
public function getType() : string {
return 'Expr_NullsafeMethodCall';
}
public function getRawArgs(): array {
return $this->args;
}
}

View File

@ -7,6 +7,7 @@ A::foo(...);
// These are invalid, but accepted on the parser level.
new Foo(...);
$this?->foo(...);
#[Foo(...)]
function foo() {}
@ -75,7 +76,21 @@ array(
0: // These are invalid, but accepted on the parser level.
)
)
4: Stmt_Function(
4: Stmt_Expression(
expr: Expr_NullsafeMethodCall(
var: Expr_Variable(
name: this
)
name: Identifier(
name: foo
)
args: array(
0: VariadicPlaceholder(
)
)
)
)
5: Stmt_Function(
attrGroups: array(
0: AttributeGroup(
attrs: array(