Mercurial > hg > isophonics-drupal-site
diff vendor/psy/psysh/src/Command/ThrowUpCommand.php @ 16:c2387f117808
Routine composer update
author | Chris Cannam |
---|---|
date | Tue, 10 Jul 2018 15:07:59 +0100 |
parents | 5fb285c0d0e3 |
children | 129ea1e6d783 |
line wrap: on
line diff
--- a/vendor/psy/psysh/src/Command/ThrowUpCommand.php Thu Apr 26 11:26:54 2018 +0100 +++ b/vendor/psy/psysh/src/Command/ThrowUpCommand.php Tue Jul 10 15:07:59 2018 +0100 @@ -12,9 +12,11 @@ namespace Psy\Command; use PhpParser\Node\Arg; +use PhpParser\Node\Expr\New_; use PhpParser\Node\Expr\StaticCall; use PhpParser\Node\Expr\Variable; use PhpParser\Node\Name\FullyQualified as FullyQualifiedName; +use PhpParser\Node\Scalar\String_; use PhpParser\Node\Stmt\Throw_; use PhpParser\PrettyPrinter\Standard as Printer; use Psy\Context; @@ -85,6 +87,7 @@ <return>>>> throw-up</return> <return>>>> throw-up $e</return> <return>>>> throw-up new Exception('WHEEEEEE!')</return> +<return>>>> throw-up "bye!"</return> HELP ); } @@ -126,13 +129,24 @@ $code = '<?php ' . $code; } - $expr = $this->parse($code); - - if (count($expr) !== 1) { + $nodes = $this->parse($code); + if (count($nodes) !== 1) { throw new \InvalidArgumentException('No idea how to throw this'); } - return [new Arg($expr[0])]; + $node = $nodes[0]; + + // Make this work for PHP Parser v3.x + $expr = isset($node->expr) ? $node->expr : $node; + + $args = [new Arg($expr, false, false, $node->getAttributes())]; + + // Allow throwing via a string, e.g. `throw-up "SUP"` + if ($expr instanceof String_) { + return [new New_(new FullyQualifiedName('Exception'), $args)]; + } + + return $args; } /**