ClearCommand::execute()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 1
Metric Value
eloc 8
c 2
b 0
f 1
dl 0
loc 14
ccs 9
cts 9
cp 1
rs 10
cc 2
nc 2
nop 2
crap 2
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