ChainFactory   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 26
rs 10
c 0
b 0
f 0
ccs 0
cts 12
cp 0
wmc 4
lcom 0
cbo 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A createExecutionChain() 0 20 4
1
<?php
2
declare(strict_types=1);
3
4
/**
5
 * This file is part of phpDocumentor.
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 * @copyright 2010-2018 Mike van Riel / Naenius (http://www.naenius.com)
11
 * @license   http://www.opensource.org/licenses/mit-license.php MIT
12
 * @link      http://phpdoc.org
13
 */
14
15
namespace phpDocumentor\Reflection\Middleware;
16
17
use InvalidArgumentException;
18
19
final class ChainFactory
20
{
21
    /**
22
     * @param Middleware[] $middlewareList
23
     */
24
    public static function createExecutionChain(array $middlewareList, callable $lastCallable): callable
25
    {
26
        while ($middleware = array_pop($middlewareList)) {
27
            if (!$middleware instanceof Middleware) {
28
                throw new InvalidArgumentException(
29
                    sprintf(
30
                        'Middleware must be an instance of %s but %s was given',
31
                        Middleware::class,
32
                        is_object($middleware) ? get_class($middleware) : gettype($middleware)
33
                    )
34
                );
35
            }
36
37
            $lastCallable = function ($command) use ($middleware, $lastCallable) {
38
                return $middleware->execute($command, $lastCallable);
39
            };
40
        }
41
42
        return $lastCallable;
43
    }
44
}
45