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

QueryBuilderGeneratorCommand   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 2
c 1
b 0
f 1
lcom 1
cbo 5
dl 0
loc 27
ccs 0
cts 16
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 9 1
A execute() 0 9 1
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\QueryBuilderGenerator;
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\Input\InputOption;
13
use Symfony\Component\Console\Output\OutputInterface;
14
15
final class QueryBuilderGeneratorCommand extends Command
16
{
17
    protected function configure()
18
    {
19
        $this
20
            ->setName('saxulum:elasticsearch:querybuilder:generator:querybuilder')
21
            ->setDescription('Generate the node code of a elasticsearch json query.')
22
            ->addArgument('query', InputArgument::REQUIRED, 'The json query.')
23
            ->addOption('useMethodName', 'm', InputOption::VALUE_NONE, 'Use method names as addToObjectNode')
24
        ;
25
    }
26
27
    /**
28
     * @param InputInterface  $input
29
     * @param OutputInterface $output
30
     * @return int
31
     */
32
    protected function execute(InputInterface $input, OutputInterface $output)
33
    {
34
        $generator = new QueryBuilderGenerator(new PhpGenerator(), $input->getOption('useMethodName'));
35
36
        $output->writeln('<info>Generated code:</info>');
37
        $output->writeln($generator->generateByJson($input->getArgument('query')));
38
39
        return 0;
40
    }
41
}
42