Completed
Push — master ( e6daa6...fa6903 )
by Márk
05:04 queued 03:08
created

QueueMiddleware::execute()   A

Complexity

Conditions 4
Paths 5

Size

Total Lines 18
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 4.0961

Importance

Changes 0
Metric Value
dl 0
loc 18
ccs 9
cts 11
cp 0.8182
rs 9.2
c 0
b 0
f 0
cc 4
eloc 9
nc 5
nop 2
crap 4.0961
1
<?php
2
3
namespace League\Tactician\Bernard;
4
5
use Bernard\Message;
6
use Bernard\Producer;
7
use League\Tactician\Command;
8
use League\Tactician\Middleware;
9
10
/**
11
 * Sends the command to a remote location using message queues
12
 */
13
class QueueMiddleware implements Middleware
14
{
15
    /**
16
     * @var Producer
17
     */
18
    protected $producer;
19
20
    /**
21
     * @param Producer $producer
22
     */
23 5
    public function __construct(Producer $producer)
24
    {
25 5
        $this->producer = $producer;
26 5
    }
27
28
    /**
29
     * {@inheritdoc}
30
     */
31 3
    public function execute($command, callable $next)
32
    {
33 3
        if ($command instanceof Message) {
34 1
            $this->producer->produce($command);
35
36 1
            return;
37
        }
38
39 2
        if ($command instanceof QueuedCommand) {
40 1
            $command = $command->getCommand();
41 1
        }
42
43 2
        if ($command instanceof QueueCommand) {
44
            $command = $command->getCommand();
45
        }
46
47 2
        return $next($command);
48
    }
49
}
50