NodeGeneratorCommand::execute()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 9
Ratio 100 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
dl 9
loc 9
ccs 5
cts 5
cp 1
rs 9.9666
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 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\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\Input\InputOption;
13
use Symfony\Component\Console\Output\OutputInterface;
14
15
final class NodeGeneratorCommand extends Command
16
{
17 2
    protected function configure()
18
    {
19
        $this
20 2
            ->setName('saxulum:elasticsearch:querybuilder:generator:node')
21 2
            ->setDescription('Generate the node code of a elasticsearch json query.')
22 2
            ->addArgument('query', InputArgument::REQUIRED, 'The json query.')
23 2
            ->addOption('useQueryBuilderFactory', 'f', InputOption::VALUE_NONE, 'Use query builder factory')
24
        ;
25 2
    }
26
27
    /**
28
     * @param InputInterface  $input
29
     * @param OutputInterface $output
30
     *
31
     * @return int
32
     */
33 2 View Code Duplication
    protected function execute(InputInterface $input, OutputInterface $output)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
34
    {
35 2
        $generator = new NodeGenerator(new PhpGenerator(), $input->getOption('useQueryBuilderFactory'));
36
37 2
        $output->writeln('<info>Generated code:</info>');
38 2
        $output->writeln($generator->generateByJson($input->getArgument('query')));
39
40 2
        return 0;
41
    }
42
}
43