Application::configure()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
dl 0
loc 6
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace PHPTdGram\SchemaGenerator\Console;
6
7
use PHPTdGram\SchemaGenerator\CodeGenerator;
8
use PHPTdGram\SchemaGenerator\SchemaParser;
9
use Symfony\Component\Console\Application as SfApplication;
10
use Symfony\Component\Console\Command\Command;
11
use Symfony\Component\Console\Input\InputArgument;
12
use Symfony\Component\Console\Input\InputInterface;
13
use Symfony\Component\Console\Output\OutputInterface;
14
15
/**
16
 * @author  Aurimas Niekis <[email protected]>
17
 */
18
class Application extends Command
19
{
20
    private string $version = '1.0';
21
    private bool   $running = false;
22
23
    public function run(InputInterface $input = null, OutputInterface $output = null): int
24
    {
25
        if ($this->running) {
26
            return parent::run($input, $output);
0 ignored issues
show
Bug introduced by
It seems like $output can also be of type null; however, parameter $output of Symfony\Component\Console\Command\Command::run() does only seem to accept Symfony\Component\Console\Output\OutputInterface, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

26
            return parent::run($input, /** @scrutinizer ignore-type */ $output);
Loading history...
Bug introduced by
It seems like $input can also be of type null; however, parameter $input of Symfony\Component\Console\Command\Command::run() does only seem to accept Symfony\Component\Console\Input\InputInterface, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

26
            return parent::run(/** @scrutinizer ignore-type */ $input, $output);
Loading history...
27
        }
28
29
        $application = new SfApplication($this->getName() ?: 'UNKNOWN', $this->version);
30
31
        $this->setName($_SERVER['argv'][0]);
32
        $application->add($this);
33
        $application->setDefaultCommand($this->getName(), true);
34
35
        $this->running = true;
36
37
        try {
38
            $ret = $application->run($input, $output);
39
        } finally {
40
            $this->running = false;
41
        }
42
43
        return $ret ?? 1;
44
    }
45
46
    protected function configure(): void
47
    {
48
        $this->addArgument(
49
            'tl_file',
50
            InputArgument::OPTIONAL,
51
            'Telegram TL file to generate classes from'
52
        );
53
    }
54
55
    protected function execute(InputInterface $input, OutputInterface $output)
56
    {
57
        $parser  = new SchemaParser($output, $input->getArgument('tl_file'));
0 ignored issues
show
Bug introduced by
It seems like $input->getArgument('tl_file') can also be of type string[]; however, parameter $schemaFile of PHPTdGram\SchemaGenerato...maParser::__construct() does only seem to accept null|string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

57
        $parser  = new SchemaParser($output, /** @scrutinizer ignore-type */ $input->getArgument('tl_file'));
Loading history...
58
        $classes = $parser->parse();
59
60
        $generator = new CodeGenerator('PHPTdGram\Schema', __DIR__ . '/../../schema/src');
61
        $generator->generate($classes);
62
63
        return 0;
64
    }
65
}
66