upgraded dependencies
This commit is contained in:
50
vendor/psy/psysh/src/Command/ParseCommand.php
vendored
50
vendor/psy/psysh/src/Command/ParseCommand.php
vendored
@@ -3,7 +3,7 @@
|
||||
/*
|
||||
* This file is part of Psy Shell.
|
||||
*
|
||||
* (c) 2012-2018 Justin Hileman
|
||||
* (c) 2012-2022 Justin Hileman
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
@@ -46,7 +46,7 @@ class ParseCommand extends Command implements ContextAware, PresenterAware
|
||||
public function __construct($name = null)
|
||||
{
|
||||
$this->parserFactory = new ParserFactory();
|
||||
$this->parsers = [];
|
||||
$this->parsers = [];
|
||||
|
||||
parent::__construct($name);
|
||||
}
|
||||
@@ -70,14 +70,14 @@ class ParseCommand extends Command implements ContextAware, PresenterAware
|
||||
{
|
||||
$this->presenter = clone $presenter;
|
||||
$this->presenter->addCasters([
|
||||
'PhpParser\Node' => function (Node $node, array $a) {
|
||||
Node::class => function (Node $node, array $a) {
|
||||
$a = [
|
||||
Caster::PREFIX_VIRTUAL . 'type' => $node->getType(),
|
||||
Caster::PREFIX_VIRTUAL . 'attributes' => $node->getAttributes(),
|
||||
Caster::PREFIX_VIRTUAL.'type' => $node->getType(),
|
||||
Caster::PREFIX_VIRTUAL.'attributes' => $node->getAttributes(),
|
||||
];
|
||||
|
||||
foreach ($node->getSubNodeNames() as $name) {
|
||||
$a[Caster::PREFIX_VIRTUAL . $name] = $node->$name;
|
||||
$a[Caster::PREFIX_VIRTUAL.$name] = $node->$name;
|
||||
}
|
||||
|
||||
return $a;
|
||||
@@ -90,23 +90,17 @@ class ParseCommand extends Command implements ContextAware, PresenterAware
|
||||
*/
|
||||
protected function configure()
|
||||
{
|
||||
$definition = [
|
||||
new CodeArgument('code', CodeArgument::REQUIRED, 'PHP code to parse.'),
|
||||
new InputOption('depth', '', InputOption::VALUE_REQUIRED, 'Depth to parse.', 10),
|
||||
];
|
||||
|
||||
if ($this->parserFactory->hasKindsSupport()) {
|
||||
$msg = 'One of PhpParser\\ParserFactory constants: '
|
||||
. \implode(', ', ParserFactory::getPossibleKinds())
|
||||
. " (default is based on current interpreter's version).";
|
||||
$defaultKind = $this->parserFactory->getDefaultKind();
|
||||
|
||||
$definition[] = new InputOption('kind', '', InputOption::VALUE_REQUIRED, $msg, $defaultKind);
|
||||
}
|
||||
$kindMsg = 'One of PhpParser\\ParserFactory constants: '
|
||||
.\implode(', ', ParserFactory::getPossibleKinds())
|
||||
." (default is based on current interpreter's version).";
|
||||
|
||||
$this
|
||||
->setName('parse')
|
||||
->setDefinition($definition)
|
||||
->setDefinition([
|
||||
new CodeArgument('code', CodeArgument::REQUIRED, 'PHP code to parse.'),
|
||||
new InputOption('depth', '', InputOption::VALUE_REQUIRED, 'Depth to parse.', 10),
|
||||
new InputOption('kind', '', InputOption::VALUE_REQUIRED, $kindMsg, $this->parserFactory->getDefaultKind()),
|
||||
])
|
||||
->setDescription('Parse PHP code and show the abstract syntax tree.')
|
||||
->setHelp(
|
||||
<<<'HELP'
|
||||
@@ -128,13 +122,13 @@ HELP
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$code = $input->getArgument('code');
|
||||
if (\strpos('<?', $code) === false) {
|
||||
$code = '<?php ' . $code;
|
||||
if (\strpos($code, '<?') === false) {
|
||||
$code = '<?php '.$code;
|
||||
}
|
||||
|
||||
$parserKind = $this->parserFactory->hasKindsSupport() ? $input->getOption('kind') : null;
|
||||
$depth = $input->getOption('depth');
|
||||
$nodes = $this->parse($this->getParser($parserKind), $code);
|
||||
$parserKind = $input->getOption('kind');
|
||||
$depth = $input->getOption('depth');
|
||||
$nodes = $this->parse($this->getParser($parserKind), $code);
|
||||
$output->page($this->presenter->present($nodes, $depth));
|
||||
|
||||
$this->context->setReturnValue($nodes);
|
||||
@@ -150,7 +144,7 @@ HELP
|
||||
*
|
||||
* @return array Statements
|
||||
*/
|
||||
private function parse(Parser $parser, $code)
|
||||
private function parse(Parser $parser, string $code): array
|
||||
{
|
||||
try {
|
||||
return $parser->parse($code);
|
||||
@@ -160,7 +154,7 @@ HELP
|
||||
}
|
||||
|
||||
// If we got an unexpected EOF, let's try it again with a semicolon.
|
||||
return $parser->parse($code . ';');
|
||||
return $parser->parse($code.';');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -171,7 +165,7 @@ HELP
|
||||
*
|
||||
* @return Parser
|
||||
*/
|
||||
private function getParser($kind = null)
|
||||
private function getParser(string $kind = null): Parser
|
||||
{
|
||||
if (!\array_key_exists($kind, $this->parsers)) {
|
||||
$this->parsers[$kind] = $this->parserFactory->createParser($kind);
|
||||
|
Reference in New Issue
Block a user