Skip to content

Commit

Permalink
Make NullsafeMethodCall extend from CallLike
Browse files Browse the repository at this point in the history
  • Loading branch information
nikic committed Nov 14, 2021
1 parent 6f1f206 commit 4122ff3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
17 changes: 11 additions & 6 deletions lib/PhpParser/Node/Expr/NullsafeMethodCall.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,24 @@
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;
Expand All @@ -37,4 +38,8 @@ public function getSubNodeNames() : array {
public function getType() : string {
return 'Expr_NullsafeMethodCall';
}

public function getRawArgs(): array {
return $this->args;
}
}
17 changes: 16 additions & 1 deletion test/code/parser/expr/firstClassCallables.test
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ A::foo(...);

// These are invalid, but accepted on the parser level.
new Foo(...);
$this?->foo(...);

#[Foo(...)]
function foo() {}
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 4122ff3

Please sign in to comment.