GrammarCompileCommand   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 3
dl 0
loc 49
ccs 0
cts 13
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A execute() 0 9 1
A configure() 0 5 1
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\InputInterface;
16
use Symfony\Component\Console\Output\OutputInterface;
17
18
/**
19
 * Class GrammarCompileCommand
20
 */
21
final class GrammarCompileCommand extends Command
22
{
23
    /**
24
     * @var string Default parser output path
25
     */
26
    private const PARSER_GRAMMAR = __DIR__ . '/../../resources/grammar.pp2';
27
28
    /**
29
     * @var string Default parser output path
30
     */
31
    private const OUT_PATH = __DIR__ . '/../Grammar';
32
33
    /**
34
     * @var string Default generated parser class name
35
     */
36
    private const OUT_CLASS_NAME = 'Parser';
37
38
    /**
39
     * @var string Default generated parser class name
40
     */
41
    private const OUT_NAMESPACE = 'Railt\\Compiler\\Grammar';
42
43
    /**
44
     * @param InputInterface $in
45
     * @param OutputInterface $out
46
     * @throws \Railt\Io\Exception\ExternalFileException
47
     * @throws \Railt\Io\Exception\NotReadableException
48
     * @throws \Throwable
49
     */
50
    public function execute(InputInterface $in, OutputInterface $out): void
51
    {
52
        $compiler = Compiler::load(File::fromPathname(self::PARSER_GRAMMAR));
0 ignored issues
show
Bug introduced by
It seems like \Railt\Io\File::fromPathname(self::PARSER_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...
53
54
        $compiler
55
            ->setNamespace(self::OUT_NAMESPACE)
56
            ->setClassName(self::OUT_CLASS_NAME)
57
            ->saveTo(self::OUT_PATH);
58
    }
59
60
    /**
61
     * @return void
62
     * @throws \Symfony\Component\Console\Exception\InvalidArgumentException
63
     */
64
    protected function configure(): void
65
    {
66
        $this->setName('compiler:grammar');
67
        $this->setDescription('Builds a new grammar parser from .pp/.pp2 grammar file.');
68
    }
69
}
70