Completed
Push — develop ( c60de3...4fc294 )
by Susi
05:38
created

TruncateCommand   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 4
dl 0
loc 34
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 10 1
A execute() 0 8 2
1
<?php
2
declare(strict_types=1);
3
4
namespace T3G\Elasticorn\Commands\Type;
5
6
7
use Psr\Log\LogLevel;
8
use Symfony\Component\Console\Command\Command;
9
use Symfony\Component\Console\Input\InputArgument;
10
use Symfony\Component\Console\Input\InputInterface;
11
use Symfony\Component\Console\Output\OutputInterface;
12
use T3G\Elasticorn\Commands\BaseCommand;
13
14
/**
15
 * Class TruncateCommand
16
 *
17
 * Command to truncate specified document type from index
18
 *
19
 * @package T3G\Elasticorn\Commands
20
 */
21
class TruncateCommand extends BaseCommand
22
{
23
    /**
24
     * Configure the init command
25
     *
26
     * @return void
27
     */
28
    protected function configure()
29
    {
30
        parent::configure();
31
        $this
32
            ->setName('type:truncate')
33
            ->setDescription('Truncates given document type (removes all documents of type).');
34
35
        $this->addArgument('indexName', InputArgument::REQUIRED, 'The index name.');
36
        $this->addArgument('documentType', InputArgument::REQUIRED, 'The document type to truncate.');
37
    }
38
39
    /**
40
     * @param InputInterface $input
41
     * @param OutputInterface $output
42
     *
43
     * @return void
44
     */
45
    protected function execute(InputInterface $input, OutputInterface $output)
46
    {
47
        try {
48
            $this->documentTypeService->deleteDocumentsOfType();
49
        } catch (\InvalidArgumentException $e) {
50
            $output->writeln('<error>' . $e->getMessage() . '</error>');
51
        }
52
    }
53
54
}