ExecutorChain::execute()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

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