Completed
Pull Request — master (#40)
by Márk
11:43
created

QueueAllMiddleware   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 14
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 1
dl 0
loc 14
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A execute() 0 8 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
    public function execute($command, callable $next)
19
    {
20
        if (!$command instanceof Message && !$command instanceof QueuedCommand) {
21
            $command = new QueueCommand($command);
22
        }
23
24
        return $next($command);
25
    }
26
}
27