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

QueueAllMiddleware::execute()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 8
c 0
b 0
f 0
ccs 5
cts 5
cp 1
rs 9.4285
cc 3
eloc 4
nc 2
nop 2
crap 3
1
<?php
2
3
namespace League\Tactician\Bernard;
4
5
use Bernard\Message;
6
use League\Tactician\Middleware;
7
8
/**
9
 * Makes all commands queueable (except the ones that already come from a queue to prevent loops).
10
 *
11
 * Should be placed before {@link League\Tactician\Bernard\QueueMiddleware} in the middleware chain.
12
 */
13
class QueueAllMiddleware implements Middleware
14
{
15
    /**
16
     * {@inheritdoc}
17
     */
18 3
    public function execute($command, callable $next)
19
    {
20 3
        if (!$command instanceof Message && !$command instanceof QueuedCommand) {
21 1
            $command = new QueueCommand($command);
22 1
        }
23
24 3
        return $next($command);
25
    }
26
}
27