Completed
Pull Request — master (#1)
by Dominik
05:50
created

QueryBuilderGeneratorCommand::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
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\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
/**
16
 * @deprecated use Saxulum\ElasticSearchQueryBuilder\Generator\Command\NodeGeneratorCommand
17
 */
18
final class QueryBuilderGeneratorCommand extends Command
19
{
20
    /**
21
     * @param string|null $name
22
     */
23 2
    public function __construct($name = null)
24
    {
25 2
        parent::__construct($name);
26
27 2
        @trigger_error(sprintf('Use "%s" instead of the "%s"', NodeGeneratorCommand::class, self::class), E_USER_DEPRECATED);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
28 2
    }
29
30 2
    protected function configure()
31
    {
32
        $this
33 2
            ->setName('saxulum:elasticsearch:querybuilder:generator:querybuilder')
34 2
            ->setDescription('Generate the node code of a elasticsearch json query.')
35 2
            ->addArgument('query', InputArgument::REQUIRED, 'The json query.')
36 2
            ->addOption('useMethodName', 'm', InputOption::VALUE_NONE, 'Use method names as addToObjectNode')
37
        ;
38 2
    }
39
40
    /**
41
     * @param InputInterface  $input
42
     * @param OutputInterface $output
43
     *
44
     * @return int
45
     */
46 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...
47
    {
48 2
        $generator = new QueryBuilderGenerator(new PhpGenerator(), $input->getOption('useMethodName'));
0 ignored issues
show
Deprecated Code introduced by
The class Saxulum\ElasticSearchQue...r\QueryBuilderGenerator has been deprecated with message: use Saxulum\ElasticSearchQueryBuilder\Generator\NodeGenerator

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
49
50 2
        $output->writeln('<info>Generated code:</info>');
51 2
        $output->writeln($generator->generateByJson($input->getArgument('query')));
52
53 2
        return 0;
54
    }
55
}
56