ChainedStrategy   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 37
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 37
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A addStrategy() 0 6 1
A produceQueues() 0 14 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Lamoda\TacticianQueue\Middleware\QueueProducerStrategy;
6
7
final class ChainedStrategy implements QueueProducerStrategyInterface
8
{
9
    /**
10
     * @var QueueProducerStrategyInterface[]
11
     */
12
    private $strategies;
13
14
    /**
15
     * @param QueueProducerStrategyInterface[] $strategies
16
     */
17 3
    public function __construct(array $strategies = [])
18
    {
19 3
        $this->strategies = $strategies;
20 3
    }
21
22 1
    public function addStrategy(QueueProducerStrategyInterface $strategy): self
23
    {
24 1
        $this->strategies[] = $strategy;
25
26 1
        return $this;
27
    }
28
29 3
    public function produceQueues($command): array
30
    {
31 3
        $jobs = [];
32
33 3
        foreach ($this->strategies as $strategy) {
34 2
            $jobs[] = $strategy->produceQueues($command);
35
        }
36
37 3
        if (!$jobs) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $jobs of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
38 1
            return [];
39
        }
40
41 2
        return array_merge(...$jobs);
42
    }
43
}
44