ClearCommand::configure()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
dl 0
loc 6
ccs 5
cts 5
cp 1
rs 10
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Lamoda\CleanerBundle\Command;
6
7
use Psr\Container\ContainerInterface;
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
13
class ClearCommand extends Command
14
{
15
    /** @var ContainerInterface */
16
    private $container;
17
18 4
    public function __construct(ContainerInterface $container)
19
    {
20 4
        parent::__construct();
21
22 4
        $this->container = $container;
23 4
    }
24
25 4
    protected function configure()
26
    {
27 4
        $this->setName('cleaner:clear')
28 4
            ->setDescription('Executes storage cleaners')
29 4
            ->addArgument('group', InputArgument::REQUIRED, 'Storage group')
30 4
            ->addArgument('cleaner', InputArgument::OPTIONAL, 'Cleaner name');
31 4
    }
32
33 3
    protected function execute(InputInterface $input, OutputInterface $output): int
34
    {
35 3
        $groupName = $input->getArgument('group');
36 3
        $cleanerName = $input->getArgument('cleaner');
37
38 3
        $serviceName = 'lamoda_cleaner.' . $groupName;
39 3
        if ($cleanerName != '') {
40 2
            $serviceName .= '.' . $cleanerName;
41
        }
42
43 3
        $cleaner = $this->container->get($serviceName);
44 3
        $cleaner->clear();
45
46 3
        return 0;
47
    }
48
}
49