CompileGrammarCommand::configure()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
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