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

IndexImportCommand   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 47
Duplicated Lines 34.04 %

Coupling/Cohesion

Components 0
Dependencies 6
Metric Value
wmc 2
lcom 0
cbo 6
dl 16
loc 47
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 21 1
A execute() 16 16 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
/*
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 ONGR\ElasticsearchBundle\Service\ImportService;
15
use Symfony\Component\Console\Input\InputArgument;
16
use Symfony\Component\Console\Input\InputInterface;
17
use Symfony\Component\Console\Input\InputOption;
18
use Symfony\Component\Console\Output\OutputInterface;
19
20
/**
21
 * IndexImportCommand class.
22
 */
23
class IndexImportCommand extends AbstractManagerAwareCommand
24
{
25
    /**
26
     * {@inheritdoc}
27
     */
28
    protected function configure()
29
    {
30
        parent::configure();
31
32
        $this
33
            ->setName('ongr:es:index:import')
34
            ->setDescription('Imports data to elasticsearch index.')
35
            ->addArgument(
36
                'filename',
37
                InputArgument::REQUIRED,
38
                'Select file to store output'
39
            )
40
            ->addOption(
41
                'bulk-size',
42
                'b',
43
                InputOption::VALUE_REQUIRED,
44
                'Set bulk size for import',
45
                1000
46
            )
47
            ->addOption('raw', null, InputOption::VALUE_NONE);
48
    }
49
50
    /**
51
     * {@inheritdoc}
52
     */
53 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...
54
    {
55
        $manager = $this->getManager($input->getOption('manager'));
56
57
        /** @var ImportService $importService */
58
        $importService = $this->getContainer()->get('es.import');
59
        $importService->importIndex(
60
            $manager,
61
            $input->getArgument('filename'),
62
            $input->getOption('raw'),
63
            $output,
64
            $input->getOption('bulk-size')
65
        );
66
67
        $output->writeln('<info>Data import completed!</info>');
68
    }
69
}
70