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

QueueMiddleware   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 85.71%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 3
dl 0
loc 37
ccs 12
cts 14
cp 0.8571
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A execute() 0 18 4
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