Completed
Push — master ( c3c10e...e14ee7 )
by Dominik
03:30
created

NodeGeneratorCommand::execute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 9
ccs 0
cts 7
cp 0
rs 9.6666
cc 1
eloc 5
nc 1
nop 2
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Saxulum\ElasticSearchQueryBuilder\Generator\Command;
6
7
use PhpParser\PrettyPrinter\Standard as PhpGenerator;
8
use Saxulum\ElasticSearchQueryBuilder\Generator\NodeGenerator;
9
use Symfony\Component\Console\Command\Command;
10
use Symfony\Component\Console\Input\InputArgument;
11
use Symfony\Component\Console\Input\InputInterface;
12
use Symfony\Component\Console\Output\OutputInterface;
13
14
final class NodeGeneratorCommand extends Command
15
{
16
    protected function configure()
17
    {
18
        $this
19
            ->setName('saxulum:elasticsearch:querybuilder:generator:node')
20
            ->setDescription('Generate the node code of a elasticsearch json query.')
21
            ->addArgument('query', InputArgument::REQUIRED, 'The json query.')
22
        ;
23
    }
24
25
    /**
26
     * @param InputInterface  $input
27
     * @param OutputInterface $output
28
     * @return int
29
     */
30
    protected function execute(InputInterface $input, OutputInterface $output)
31
    {
32
        $generator = new NodeGenerator(new PhpGenerator());
33
34
        $output->writeln('<info>Generated code:</info>');
35
        $output->writeln($generator->generateByJson($input->getArgument('query')));
36
37
        return 0;
38
    }
39
}
40