GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

CommandBus   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 93.33%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 0
loc 48
ccs 14
cts 15
cp 0.9333
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A execute() 0 6 1
A generateMiddlewareCallChain() 0 17 3
1
<?php
2
namespace SmoothPhp\CommandBus;
3
4
use SmoothPhp\CommandBus\Exception\InvalidMiddlewareException;
5
use SmoothPhp\Contracts\CommandBus\Command;
6
use SmoothPhp\Contracts\CommandBus\CommandBusMiddleware;
7
8
/**
9
 * Class CommandBus
10
 * @package SmoothPhp\CommandBus
11
 * @author Simon Bennett <[email protected]>
12
 */
13
final class CommandBus implements \SmoothPhp\Contracts\CommandBus\CommandBus
14
{
15
    /**
16
     * @var callable
17
     */
18
    private $middlewareChain;
19
20
    /**
21
     * CommandBus constructor.
22
     * @param CommandBusMiddleware[] $middleware
23
     */
24 9
    public function __construct(array $middleware)
25
    {
26 9
        $this->middlewareChain = $this->generateMiddlewareCallChain($middleware);
27 9
    }
28
29
    /**
30
     * @param Command $command
31
     */
32 9
    public function execute(Command $command)
33
    {
34 9
        $middlewareChain = $this->middlewareChain;
35
36 9
        return $middlewareChain($command);
37
    }
38
39
    /**
40
     * @param $middleware
41
     * @return \Closure
42
     */
43 9
    private function generateMiddlewareCallChain($middlewareList)
44
    {
45
        $lastCallable = function () {
46
            // the final callable does not run
47 9
        };
48
49 9
        while ($middleware = array_pop($middlewareList)) {
50 9
            if (!$middleware instanceof CommandBusMiddleware) {
51
                throw InvalidMiddlewareException::forMiddleware($middleware);
52
            }
53 9
            $lastCallable = function ($command) use ($middleware, $lastCallable) {
54 9
                return $middleware->execute($command, $lastCallable);
55 9
            };
56
        }
57
58 9
        return $lastCallable;
59
    }
60
}
61