ExecutorChain   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 6
eloc 12
c 2
b 0
f 0
dl 0
loc 34
ccs 0
cts 21
cp 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 2
A execute() 0 13 3
A add() 0 5 1
1
<?php
2
3
namespace Tarantool\JobQueue\Executor;
4
5
use Tarantool\JobQueue\Exception\BadPayloadException;
6
use Tarantool\Queue\Queue;
7
8
class ExecutorChain implements Executor
9
{
10
    /**
11
     * @var Executor[]
12
     */
13
    private $executors;
14
15
    public function __construct(array $executors = [])
16
    {
17
        foreach ($executors as $executor) {
18
            $this->add($executor);
19
        }
20
    }
21
22
    public function add(Executor $executor): self
23
    {
24
        $this->executors[] = $executor;
25
26
        return $this;
27
    }
28
29
    public function execute($payload, Queue $queue): void
30
    {
31
        foreach ($this->executors as $executor) {
32
            try {
33
                $executor->execute($payload, $queue);
34
35
                return;
36
            } catch (BadPayloadException $e) {
37
                // try next executor
38
            }
39
        }
40
41
        throw new BadPayloadException($payload);
42
    }
43
}
44