NodeGeneratorCommand   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 28
Duplicated Lines 32.14 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 5
dl 9
loc 28
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 9 1
A execute() 9 9 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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