This commit is contained in:
1 parent
f7c532a648
commit
640bd67556
5801 files changed
+484532
-55857
No files matched your search
@@ -32,4 +32,29 @@ abstract class CallLike extends Expr {
|
||||
assert(!$this->isFirstClassCallable());
|
||||
return $this->getRawArgs();
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves a specific argument from the raw arguments.
|
||||
*
|
||||
* Returns the named argument that matches the given `$name`, or the
|
||||
* positional (unnamed) argument that exists at the given `$position`,
|
||||
* otherwise, returns `null` for first-class callables or if no match is found.
|
||||
*/
|
||||
public function getArg(string $name, int $position): ?Arg {
|
||||
if ($this->isFirstClassCallable()) {
|
||||
return null;
|
||||
}
|
||||
foreach ($this->getRawArgs() as $i => $arg) {
|
||||
if ($arg->unpack) {
|
||||
continue;
|
||||
}
|
||||
if (
|
||||
($arg->name !== null && $arg->name->toString() === $name)
|
||||
|| ($arg->name === null && $i === $position)
|
||||
) {
|
||||
return $arg;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user