Completed
Push — master ( d69386...b7922a )
by Márk
11s
created

QueueMiddleware   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 3
dl 0
loc 37
ccs 14
cts 14
cp 1
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
final class QueueMiddleware implements Middleware
14
{
15
    /**
16
     * @var Producer
17
     */
18
    private $producer;
19
20
    /**
21
     * @param Producer $producer
22
     */
23 6
    public function __construct(Producer $producer)
24
    {
25 6
        $this->producer = $producer;
26 6
    }
27
28
    /**
29
     * {@inheritdoc}
30
     */
31 4
    public function execute($command, callable $next)
32
    {
33 4
        if ($command instanceof Message) {
34 1
            $this->producer->produce($command);
35
36 1
            return;
37
        }
38
39 3
        if ($command instanceof QueuedCommand) {
40 2
            $command = $command->getCommand();
41 2
        }
42
43 3
        if ($command instanceof QueueCommand) {
44 1
            $command = $command->getCommand();
45 1
        }
46
47 3
        return $next($command);
48
    }
49
}
50