ReportConfigurationProcessor::process()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 11
rs 10
cc 3
nc 4
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Setono\SyliusStockMovementPlugin\Processor;
6
7
use Psr\Log\LoggerAwareTrait;
8
use Setono\SyliusStockMovementPlugin\Message\Command\ProcessReportConfiguration;
9
use Setono\SyliusStockMovementPlugin\Provider\ReportConfigurationProviderInterface;
10
use Symfony\Component\Messenger\MessageBusInterface;
11
12
final class ReportConfigurationProcessor implements ReportConfigurationProcessorInterface
13
{
14
    use LoggerAwareTrait;
15
16
    /** @var ReportConfigurationProviderInterface */
17
    private $reportConfigurationProvider;
18
19
    /** @var MessageBusInterface */
20
    private $commandBus;
21
22
    public function __construct(ReportConfigurationProviderInterface $reportConfigurationProvider, MessageBusInterface $commandBus)
23
    {
24
        $this->reportConfigurationProvider = $reportConfigurationProvider;
25
        $this->commandBus = $commandBus;
26
    }
27
28
    public function process(): void
29
    {
30
        $reportConfigurations = $this->reportConfigurationProvider->getReportConfigurations();
31
32
        if (count($reportConfigurations) === 0) {
33
            $this->logger->info('No report configurations due');
34
        }
35
36
        foreach ($reportConfigurations as $reportConfiguration) {
37
            $this->logger->info('Processing report configuration: ' . $reportConfiguration->getName());
38
            $this->commandBus->dispatch(new ProcessReportConfiguration($reportConfiguration->getId()));
39
        }
40
    }
41
}
42