Passed
Branch master (a01aa4)
by Mike
03:32
created

AutoQueuingMiddleware::execute()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 1
Bugs 0 Features 1
Metric Value
dl 0
loc 7
ccs 0
cts 7
cp 0
rs 9.4285
c 1
b 0
f 1
cc 3
eloc 4
nc 2
nop 2
crap 12
1
<?php
2
3
namespace MGDigital\BusQue\Tactician;
4
5
use League\Tactician\Middleware;
6
use MGDigital\BusQue\AutoQueue\DeciderInterface;
7
use MGDigital\BusQue\BusQueCommandInterface;
8
use MGDigital\BusQue\QueuedCommand;
9
10
class AutoQueuingMiddleware implements Middleware
11
{
12
13
    private $decider;
14
15
    public function __construct(DeciderInterface $decider)
16
    {
17
        $this->decider = $decider;
18
    }
19
20
    public function execute($command, callable $next)
21
    {
22
        if (!$command instanceof BusQueCommandInterface && $this->decider->shouldBeQueued($command)) {
23
            $command = new QueuedCommand($command);
24
        }
25
        return $next($command);
26
    }
27
}
28