No Description

CallLike.php 1017B

123456789101112131415161718192021222324252627282930313233343536373839
  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. foreach ($this->getRawArgs() as $arg) {
  19. if ($arg instanceof VariadicPlaceholder) {
  20. return true;
  21. }
  22. }
  23. return false;
  24. }
  25. /**
  26. * Assert that this is not a first-class callable and return only ordinary Args.
  27. *
  28. * @return Arg[]
  29. */
  30. public function getArgs(): array {
  31. assert(!$this->isFirstClassCallable());
  32. return $this->getRawArgs();
  33. }
  34. }