GenerateReports   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 1
dl 0
loc 56
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A configure() 0 9 1
A execute() 0 5 1
1
<?php
2
declare(strict_types=1);
3
4
/**
5
 * File: GenerateReports.php
6
 *
7
 * @author      Maciej Sławik <[email protected]>
8
 * Github:      https://github.com/maciejslawik
9
 */
10
11
namespace MSlwk\ReactPhpPlayground\Console\Command;
12
13
use Magento\Framework\Serialize\Serializer\Json;
14
use MSlwk\ReactPhpPlayground\Api\Report\CliReportManagerInterface;
15
use Symfony\Component\Console\Command\Command;
16
use Symfony\Component\Console\Input\InputArgument;
17
use Symfony\Component\Console\Input\InputInterface;
18
use Symfony\Component\Console\Output\OutputInterface;
19
20
/**
21
 * Class GenerateReports
22
 * @package MSlwk\ReactPhpPlayground\Console\Command
23
 */
24
class GenerateReports extends Command
25
{
26
    const COMMAND_NAME = 'mslwk:generate-reports';
27
    const COMMAND_DESCRIPTION = 'Generate reports for customers with IDs supplied';
28
    const ARGUMENT_CUSTOMER_IDS = 'customer-ids';
29
30
    /**
31
     * @var Json
32
     */
33
    private $jsonHandler;
34
35
    /**
36
     * @var CliReportManagerInterface
37
     */
38
    private $reportManager;
39
40
    /**
41
     * GenerateReports constructor.
42
     * @param Json $jsonHandler
43
     * @param CliReportManagerInterface $reportManager
44
     * @param null $name
45
     */
46
    public function __construct(
47
        Json $jsonHandler,
48
        CliReportManagerInterface $reportManager,
49
        $name = null
50
    ) {
51
        parent::__construct($name);
52
        $this->jsonHandler = $jsonHandler;
53
        $this->reportManager = $reportManager;
54
    }
55
56
    /**
57
     * {@inheritdoc}
58
     */
59
    protected function configure()
60
    {
61
        $this->setName(self::COMMAND_NAME)
62
            ->setDescription(self::COMMAND_DESCRIPTION)
63
            ->addArgument(
64
                self::ARGUMENT_CUSTOMER_IDS,
65
                InputArgument::REQUIRED
66
            );
67
    }
68
69
    /**
70
     * @param InputInterface $input
71
     * @param OutputInterface $output
72
     * @return void
73
     */
74
    protected function execute(InputInterface $input, OutputInterface $output)
75
    {
76
        $customerIds = $this->jsonHandler->unserialize($input->getArgument(self::ARGUMENT_CUSTOMER_IDS));
77
        $this->reportManager->generateAndSendReportForCustomers($customerIds);
78
    }
79
}
80