1 | <?php |
||||
2 | |||||
3 | declare(strict_types=1); |
||||
4 | |||||
5 | namespace AurimasNiekis\TdLibSchema\Generator; |
||||
6 | |||||
7 | use AurimasNiekis\TdLibSchema\Generator\Parser\SchemaParser; |
||||
8 | use Monolog\Logger; |
||||
9 | use Symfony\Bridge\Monolog\Handler\ConsoleHandler; |
||||
10 | use Symfony\Component\Console\Application; |
||||
11 | use Symfony\Component\Console\Command\Command; |
||||
12 | use Symfony\Component\Console\Input\InputArgument; |
||||
13 | use Symfony\Component\Console\Input\InputInterface; |
||||
14 | use Symfony\Component\Console\Output\OutputInterface; |
||||
15 | |||||
16 | /** |
||||
17 | * @author Aurimas Niekis <[email protected]> |
||||
18 | */ |
||||
19 | class ConsoleApplication extends Command |
||||
20 | { |
||||
21 | private string $version = '1.0'; |
||||
22 | private bool $running = false; |
||||
23 | |||||
24 | public function run(InputInterface $input = null, OutputInterface $output = null): int |
||||
25 | { |
||||
26 | if ($this->running) { |
||||
27 | 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
![]() |
|||||
28 | } |
||||
29 | |||||
30 | // We use the command name as the application name |
||||
31 | $application = new Application($this->getName() ?: 'UNKNOWN', $this->version); |
||||
32 | |||||
33 | // Fix the usage of the command displayed with "--help" |
||||
34 | $this->setName($_SERVER['argv'][0]); |
||||
35 | $application->add($this); |
||||
36 | $application->setDefaultCommand($this->getName(), true); |
||||
37 | |||||
38 | $this->running = true; |
||||
39 | |||||
40 | try { |
||||
41 | $ret = $application->run($input, $output); |
||||
42 | } finally { |
||||
43 | $this->running = false; |
||||
44 | } |
||||
45 | |||||
46 | return $ret ?? 1; |
||||
47 | } |
||||
48 | |||||
49 | protected function configure(): void |
||||
50 | { |
||||
51 | $this->addArgument( |
||||
52 | 'tl_file', |
||||
53 | InputArgument::OPTIONAL, |
||||
54 | 'Telegram TL file to generate classes from' |
||||
55 | ); |
||||
56 | } |
||||
57 | |||||
58 | protected function execute(InputInterface $input, OutputInterface $output) |
||||
59 | { |
||||
60 | $logger = new Logger('generator'); |
||||
61 | $logger->pushHandler(new ConsoleHandler($output)); |
||||
62 | |||||
63 | $parser = new SchemaParser($logger, $input->getArgument('tl_file')); |
||||
0 ignored issues
–
show
It seems like
$input->getArgument('tl_file') can also be of type string[] ; however, parameter $schemaFile of AurimasNiekis\TdLibSchem...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
![]() |
|||||
64 | $classes = $parser->parse(); |
||||
65 | |||||
66 | $generator = new CodeGenerator('AurimasNiekis\TdLibSchema', __DIR__ . '/../src'); |
||||
67 | $generator->generate($classes); |
||||
68 | |||||
69 | return 0; |
||||
70 | } |
||||
71 | } |
||||
72 |