CommandsListToCommandJobStrategy   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 0
loc 44
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A produceQueues() 0 16 4
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Lamoda\TacticianQueue\Middleware\QueueProducerStrategy;
6
7
use Lamoda\TacticianQueue\Job\CommandJob;
8
9
final class CommandsListToCommandJobStrategy implements QueueProducerStrategyInterface
10
{
11
    /**
12
     * @var string
13
     */
14
    private $queue;
15
    /**
16
     * @var string
17
     */
18
    private $exchange;
19
    /**
20
     * @var array
21
     */
22
    private $commandsClasses;
23
    /**
24
     * @var int
25
     */
26
    private $delaySeconds;
27
28 2
    public function __construct(string $queue, string $exchange, array $commandsClasses = [], int $delaySeconds = 0)
29
    {
30 2
        $this->exchange = $exchange;
31 2
        $this->queue = $queue;
32 2
        $this->commandsClasses = $commandsClasses;
33 2
        $this->delaySeconds = $delaySeconds;
34 2
    }
35
36 2
    public function produceQueues($command): array
37
    {
38 2
        foreach ($this->commandsClasses as $commandClass) {
39 2
            if ($command instanceof $commandClass) {
40 1
                $queue = new CommandJob($command, $this->queue, $this->exchange);
41
42 1
                if ($this->delaySeconds > 0) {
43 1
                    $queue->setScheduleAt((new \DateTime())->modify('+' . $this->delaySeconds . ' second'));
44
                }
45
46 2
                return [$queue];
47
            }
48
        }
49
50 1
        return [];
51
    }
52
}
53