ExecuteCommand   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 3
eloc 16
c 2
b 0
f 0
dl 0
loc 37
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A execute() 0 8 1
A configure() 0 6 1
1
<?php
2
3
namespace Oliverde8\PhpEtlBundle\Command;
4
5
use Oliverde8\PhpEtlBundle\Services\ChainProcessorsManager;
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
11
class ExecuteCommand extends Command
12
{
13
    const ARGUMENT_NAME = "name";
14
    const ARGUMENT_DATA = "data";
15
    const ARGUMENT_PARAMS = "params";
16
17
    protected ChainProcessorsManager $chainProcessorsManager;
18
19
    /**
20
     * ExecuteCommand constructor.
21
     * @param ChainProcessorsManager $chainProcessorsManager
22
     */
23
    public function __construct(ChainProcessorsManager $chainProcessorsManager)
24
    {
25
        parent::__construct();
26
        $this->chainProcessorsManager = $chainProcessorsManager;
27
    }
28
29
    protected function configure()
30
    {
31
        $this->setName("etl:execute");
32
        $this->addArgument(self::ARGUMENT_NAME, InputArgument::REQUIRED);
33
        $this->addArgument(self::ARGUMENT_DATA, InputArgument::OPTIONAL, "json with the input array");
34
        $this->addArgument(self::ARGUMENT_PARAMS, InputArgument::OPTIONAL, "json with all the additional parameters");
35
    }
36
37
    /**
38
     * @throws \Oliverde8\Component\PhpEtl\Exception\ChainOperationException
39
     */
40
    protected function execute(InputInterface $input, OutputInterface $output)
41
    {
42
        $chainName = $input->getArgument(self::ARGUMENT_NAME);
43
        $options = json_decode($input->getArgument(self::ARGUMENT_PARAMS) ?? '[]', true);
44
        $data = json_decode($input->getArgument(self::ARGUMENT_DATA) ?? '[]', true);
45
46
        $this->chainProcessorsManager->execute($chainName, $data, $options);
47
        return 0;
48
    }
49
}
50