Completed
Push — v0.10 ( f42b97...309689 )
by Simonas
8s
created

TypeCreateCommand   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 64
Duplicated Lines 23.44 %

Coupling/Cohesion

Components 0
Dependencies 6
Metric Value
wmc 7
lcom 0
cbo 6
dl 15
loc 64
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 15 1
B execute() 15 39 6

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
/*
4
 * This file is part of the ONGR package.
5
 *
6
 * (c) NFQ Technologies UAB <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace ONGR\ElasticsearchBundle\Command;
13
14
use Symfony\Component\Console\Input\InputInterface;
15
use Symfony\Component\Console\Input\InputOption;
16
use Symfony\Component\Console\Output\OutputInterface;
17
18
/**
19
 * Command for putting mapping into elasticsearch client.
20
 */
21
class TypeCreateCommand extends AbstractManagerAwareCommand
22
{
23
    /**
24
     * {@inheritdoc}
25
     */
26
    protected function configure()
27
    {
28
        parent::configure();
29
30
        $this
31
            ->setName('ongr:es:type:create')
32
            ->setDescription('Puts mappings into elasticsearch client for specific manager.')
33
            ->addOption(
34
                'type',
35
                't',
36
                InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,
37
                'Specific types to load.',
38
                []
39
            );
40
    }
41
42
    /**
43
     * {@inheritdoc}
44
     */
45
    protected function execute(InputInterface $input, OutputInterface $output)
46
    {
47
        $manager = $input->getOption('manager');
48
        $type = $input->getOption('type');
49
50
        $connection = $this->getManager($manager)->getConnection();
51
        $status = $connection->createTypes($type);
52
53
        switch ($status) {
54 View Code Duplication
            case 0:
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
55
                $message = sprintf(
56
                    '<info>Manager `</info><comment>%s</comment><info>` does not contain%s type(s) information.</info>',
57
                    $manager,
58
                    empty($type) ? '' : ' `' . implode('</comment><info>`, `</info><comment>', $type) . '`'
59
                );
60
                break;
61 View Code Duplication
            case 1:
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
62
                $message = sprintf(
63
                    '<info>Created `</info><comment>%s</comment><info>` type(s) for manager named '
64
                    . '`</info><comment>%s</comment><info>`.</info>',
65
                    empty($type) ? 'all' : implode('</comment><info>`, `</info><comment>', $type),
66
                    $manager
67
                );
68
                break;
69
            case -1:
70
                $message = sprintf(
71
                    '<error>ATTENTION:</error> type(s) already loaded into `<comment>%s</comment>` manager.',
72
                    $manager
73
                );
74
                break;
75
            default:
76
                $message = 'Message not found.';
77
                break;
78
        }
79
80
        $output->writeln($message);
81
82
        return 0;
83
    }
84
}
85