AnalyzeCommand::execute()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 0
cts 7
cp 0
rs 9.9332
c 0
b 0
f 0
cc 2
nc 2
nop 2
crap 6
1
<?php
2
/**
3
 * This file is part of Railt package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
declare(strict_types=1);
9
10
namespace Railt\Compiler\Console;
11
12
use Railt\Compiler\Compiler;
13
use Railt\Io\File;
14
use Symfony\Component\Console\Command\Command;
15
use Symfony\Component\Console\Input\InputArgument;
16
use Symfony\Component\Console\Input\InputInterface;
17
use Symfony\Component\Console\Input\InputOption;
18
use Symfony\Component\Console\Output\OutputInterface;
19
20
/**
21
 * Class AnalyzeCommand
22
 */
23
class AnalyzeCommand extends Command
24
{
25
    /**
26
     * @param InputInterface $in
27
     * @param OutputInterface $out
28
     * @throws \Railt\Io\Exception\ExternalFileException
29
     * @throws \Railt\Io\Exception\NotReadableException
30
     * @throws \Throwable
31
     */
32
    public function execute(InputInterface $in, OutputInterface $out): void
33
    {
34
        $compiler = Compiler::load(File::fromPathname($in->getArgument('grammar')));
0 ignored issues
show
Bug introduced by
It seems like \Railt\Io\File::fromPath...getArgument('grammar')) targeting Railt\Io\File::fromPathname() can also be of type object<Railt\Io\File>; however, Railt\Compiler\Compiler::load() does only seem to accept object<Railt\Io\Readable>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
35
36
        $ast = $compiler->parse(File::fromPathname($in->getArgument('source')));
0 ignored issues
show
Bug introduced by
It seems like \Railt\Io\File::fromPath...>getArgument('source')) targeting Railt\Io\File::fromPathname() can also be of type object<Railt\Io\File>; however, Railt\Parser\Driver\Proxy::parse() does only seem to accept object<Railt\Io\Readable>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
37
38
        $ast = $in->getOption('root') ? $ast->first($in->getOption('root')) : $ast;
39
40
        $out->write((string)$ast);
41
    }
42
43
    /**
44
     * @return void
45
     * @throws \Symfony\Component\Console\Exception\InvalidArgumentException
46
     * @throws \Symfony\Component\Console\Exception\LogicException
47
     */
48
    protected function configure(): void
49
    {
50
        $this->setName('compiler:analyze');
51
        $this->setDescription('Analyze source file using selection grammar');
52
53
        $this->addArgument('grammar', InputArgument::REQUIRED,
54
            'Input pp2 grammar file');
55
56
        $this->addArgument('source', InputArgument::REQUIRED,
57
            'Input source file for parsing');
58
59
        $this->addOption('root', 'r', InputOption::VALUE_OPTIONAL,
60
            'Sets an AST root node for dumping');
61
    }
62
}
63