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.
Completed
Push — develop ( ede919...54564f )
by Simon
05:27 queued 03:15
created

CommandBus::generateMiddlewareCallChain()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 17
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 3.009

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 17
ccs 9
cts 10
cp 0.9
rs 9.4285
cc 3
eloc 8
nc 3
nop 1
crap 3.009
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 9
        }
57
58 9
        return $lastCallable;
59
    }
60
}
61