Passed
Branch develop (21f7ca)
by BENARD
04:27
created

TableCommand   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 24
dl 0
loc 51
rs 10
c 0
b 0
f 0
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A configure() 0 14 1
A execute() 0 16 3
1
<?php
2
namespace VideoGamesRecords\DwhBundle\Command;
3
4
use Exception;
5
use InvalidArgumentException;
6
use Symfony\Component\Console\Command\Command;
7
use Symfony\Component\Console\Input\InputArgument;
8
use Symfony\Component\Console\Input\InputInterface;
9
use Symfony\Component\Console\Output\OutputInterface;
10
use VideoGamesRecords\DwhBundle\Contracts\DwhInterface;
11
use VideoGamesRecords\DwhBundle\Manager\TableManager;
12
13
class TableCommand extends Command implements DwhInterface
14
{
15
    protected static $defaultName = 'vgr-dwh:table';
16
17
    private TableManager $tableManager;
18
19
    public function __construct(TableManager $tableManager)
20
    {
21
        $this->tableManager = $tableManager;
22
        parent::__construct();
23
    }
24
25
    protected function configure()
26
    {
27
        $this
28
            ->setName('vgr-dwh:table')
29
            ->setDescription('Command to update table')
30
            ->addArgument(
31
                'type',
32
                InputArgument::REQUIRED,
33
                'Strategy type'
34
            )
35
            ->addArgument(
36
                'function',
37
                InputArgument::REQUIRED,
38
                'Call function'
39
            );
40
    }
41
42
    /**
43
     * @param InputInterface  $input
44
     * @param OutputInterface $output
45
     * @return int
46
     * @throws Exception
47
     */
48
    protected function execute(InputInterface $input, OutputInterface $output): int
49
    {
50
        $type = $input->getArgument('type');
51
        $function = $input->getArgument('function');
52
53
54
        if (!array_key_exists($type, self::COMMAND_TYPES)) {
55
            throw new InvalidArgumentException(sprintf('type [%s] is invalid', $type));
56
        }
57
58
        if (!array_key_exists($function, self::COMMAND_FUNCTIONS)) {
59
            throw new InvalidArgumentException(sprintf('function [%s] is invalid', $function));
60
        }
61
62
        $this->tableManager->getStrategy($type)->$function();
63
        return Command::SUCCESS;
64
    }
65
}
66