RemapCommand::configure()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 20
rs 9.6
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
declare(strict_types = 1);
3
4
namespace T3G\Elasticorn\Commands\Index;
5
6
7
use Symfony\Component\Console\Input\InputArgument;
8
use Symfony\Component\Console\Input\InputInterface;
9
use Symfony\Component\Console\Input\InputOption;
10
use Symfony\Component\Console\Output\OutputInterface;
11
use T3G\Elasticorn\Commands\BaseCommand;
12
13
/**
14
 * Class RemapCommand
15
 *
16
 * Command for applying new mappings to index(es)
17
 *
18
 * @package T3G\Elasticorn\Commands
19
 */
20
class RemapCommand extends BaseCommand
21
{
22
    /**
23
     * Configure this command
24
     *
25
     * @return void
26
     */
27
    protected function configure()
28
    {
29
        parent::configure();
30
        $this
31
            ->setName('index:remap')
32
            ->setDescription('remap index');
33
        $this->addArgument(
34
            'indexName',
35
            InputArgument::OPTIONAL,
36
            'The name of the index to remap (if none given, all will be re-indexed.)'
37
        );
38
39
        $this->addOption(
40
            'force',
41
            'f',
42
            InputOption::VALUE_NONE,
43
            'If enabled remapping will be forced, even if there are no changes.'
44
        );
45
46
    }
47
48
    /**
49
     * @param InputInterface  $input
50
     * @param OutputInterface $output
51
     *
52
     * @return void
53
     */
54
    protected function execute(InputInterface $input, OutputInterface $output)
55
    {
56
        parent::execute($input, $output);
57
        $force = false;
58
        if ($input->getOption('force')) {
59
            $force = true;
60
        }
61
        if ($input->hasArgument('indexName') && null !== $indexName = $input->getArgument('indexName')) {
62
            $output->writeln('Remapping and recreating index ' . $indexName);
63
            $this->indexService->remap($indexName, $force);
0 ignored issues
show
Bug introduced by
It seems like $indexName defined by $input->getArgument('indexName') on line 61 can also be of type array<integer,string>; however, T3G\Elasticorn\Service\IndexService::remap() does only seem to accept string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
64
        } else {
65
            $output->writeln('Remapping and recreating all configured indices.');
66
            $this->indexService->remapAll($force);
67
        }
68
    }
69
70
}
71