CompileGrammarCommand   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 3
dl 0
loc 33
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 5 1
A execute() 0 8 1
1
<?php
2
/**
3
 * This file is part of Properties 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 Serafim\Properties\Commands;
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 CompileGrammarCommand
20
 */
21
class CompileGrammarCommand extends Command
22
{
23
    /**
24
     * @var string
25
     */
26
    private const PATH_TO_GRAMMAR = __DIR__ . '/../../resources/grammar.pp2';
27
28
    /**
29
     * @throws \Symfony\Component\Console\Exception\InvalidArgumentException
30
     */
31
    protected function configure(): void
32
    {
33
        $this->setName('compile');
34
        $this->setDescription('Compile grammar from sources');
35
    }
36
37
    /**
38
     * @param InputInterface $input
39
     * @param OutputInterface $output
40
     * @return int|null|void
41
     * @throws \Railt\Io\Exception\ExternalFileException
42
     * @throws \Railt\Io\Exception\NotReadableException
43
     * @throws \Throwable
44
     */
45
    public function execute(InputInterface $input, OutputInterface $output)
46
    {
47
        $compiler = Compiler::load(File::fromPathname(self::PATH_TO_GRAMMAR));
0 ignored issues
show
Bug introduced by
It seems like \Railt\Io\File::fromPath...(self::PATH_TO_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...
48
49
        $compiler->setNamespace('Serafim\\Properties\\Parser')
50
            ->setClassName('BaseParser')
51
            ->saveTo(__DIR__ . '/../Parser');
52
    }
53
}
54