CallLike.php 970 B

1234567891011121314151617181920212223242526272829303132333435
  1. <?php declare(strict_types=1);
  2. namespace PhpParser\Node\Expr;
  3. use PhpParser\Node\Arg;
  4. use PhpParser\Node\Expr;
  5. use PhpParser\Node\VariadicPlaceholder;
  6. abstract class CallLike extends Expr {
  7. /**
  8. * Return raw arguments, which may be actual Args, or VariadicPlaceholders for first-class
  9. * callables.
  10. *
  11. * @return array<Arg|VariadicPlaceholder>
  12. */
  13. abstract public function getRawArgs(): array;
  14. /**
  15. * Returns whether this call expression is actually a first class callable.
  16. */
  17. public function isFirstClassCallable(): bool {
  18. $rawArgs = $this->getRawArgs();
  19. return count($rawArgs) === 1 && current($rawArgs) instanceof VariadicPlaceholder;
  20. }
  21. /**
  22. * Assert that this is not a first-class callable and return only ordinary Args.
  23. *
  24. * @return Arg[]
  25. */
  26. public function getArgs(): array {
  27. assert(!$this->isFirstClassCallable());
  28. return $this->getRawArgs();
  29. }
  30. }