SelfExecutionMiddleware   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 1
dl 0
loc 19
c 0
b 0
f 0
ccs 6
cts 6
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A execute() 0 10 3
1
<?php
2
namespace Spekkionu\Tactician\SelfExecuting;
3
4
use League\Tactician\Middleware;
5
6
/**
7
 * Middleware are the plugins of Tactician. They receive each command that's
8
 * given to the CommandBus and can take any action they choose. Middleware can
9
 * continue the Command processing by passing the command they receive to the
10
 * $next callable, which is essentially the "next" Middleware in the chain.
11
 *
12
 * Depending on where they invoke the $next callable, Middleware can execute
13
 * their custom logic before or after the Command is handled. They can also
14
 * modify, log, or replace the command they receive. The sky's the limit.
15
 */
16
class SelfExecutionMiddleware implements Middleware
17
{
18
    /**
19
     * @param object $command
20
     * @param callable $next
21
     * @return mixed
22
     * @throws CommandHasNoHandleMethodException
23
     */
24 3
    public function execute($command, callable $next)
25
    {
26 3
        if (!$command instanceof SelfExecutingCommand) {
27 1
            return $next($command);
28
        }
29 2
        if (!method_exists($command, 'handle')) {
30 1
            throw new CommandHasNoHandleMethodException('Command does not have handle method');
31
        }
32 1
        return $command->handle();
0 ignored issues
show
Bug introduced by
The method handle() does not seem to exist on object<Spekkionu\Tactici...g\SelfExecutingCommand>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
33
    }
34
}
35