| 1: | <?php declare(strict_types=1); |
| 2: | |
| 3: | namespace PhpParser\Node\Expr; |
| 4: | |
| 5: | use PhpParser\Node\Arg; |
| 6: | use PhpParser\Node\ArgPlaceholder; |
| 7: | use PhpParser\Node\Expr; |
| 8: | use PhpParser\Node\VariadicPlaceholder; |
| 9: | |
| 10: | abstract class CallLike extends Expr { |
| 11: | |
| 12: | |
| 13: | |
| 14: | |
| 15: | |
| 16: | |
| 17: | abstract public function getRawArgs(): array; |
| 18: | |
| 19: | |
| 20: | |
| 21: | |
| 22: | public function isFirstClassCallable(): bool { |
| 23: | $rawArgs = $this->getRawArgs(); |
| 24: | return count($rawArgs) === 1 && current($rawArgs) instanceof VariadicPlaceholder; |
| 25: | } |
| 26: | |
| 27: | |
| 28: | |
| 29: | |
| 30: | |
| 31: | |
| 32: | |
| 33: | public function isPartialFunctionApplication(): bool { |
| 34: | foreach ($this->getRawArgs() as $arg) { |
| 35: | if ($arg instanceof VariadicPlaceholder || $arg instanceof ArgPlaceholder) { |
| 36: | return true; |
| 37: | } |
| 38: | } |
| 39: | return false; |
| 40: | } |
| 41: | |
| 42: | |
| 43: | |
| 44: | |
| 45: | |
| 46: | |
| 47: | |
| 48: | public function getArgs(): array { |
| 49: | assert(!$this->isPartialFunctionApplication()); |
| 50: | return $this->getRawArgs(); |
| 51: | } |
| 52: | |
| 53: | |
| 54: | |
| 55: | |
| 56: | |
| 57: | |
| 58: | |
| 59: | |
| 60: | |
| 61: | |
| 62: | |
| 63: | public function getArg(string $name, int $position): ?Arg { |
| 64: | foreach ($this->getRawArgs() as $i => $arg) { |
| 65: | if ($arg instanceof VariadicPlaceholder) { |
| 66: | return null; |
| 67: | } |
| 68: | if ($arg instanceof ArgPlaceholder || $arg->unpack) { |
| 69: | continue; |
| 70: | } |
| 71: | if ( |
| 72: | ($arg->name !== null && $arg->name->toString() === $name) |
| 73: | || ($arg->name === null && $i === $position) |
| 74: | ) { |
| 75: | return $arg; |
| 76: | } |
| 77: | } |
| 78: | return null; |
| 79: | } |
| 80: | } |
| 81: | |