ChainedStrategy::addStrategy()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
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