MiddlewareAwareTrait   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A middleware() 0 6 1
A middlewares() 0 8 2
A prependMiddleware() 0 6 1
A shiftMiddleware() 0 4 1
A getMiddlewareStack() 0 4 1
1
<?php declare(strict_types=1);
2
3
namespace League\Route\Middleware;
4
5
use Psr\Http\Server\MiddlewareInterface;
6
7
trait MiddlewareAwareTrait
8
{
9
    /**
10
     * @var \Psr\Http\Server\MiddlewareInterface[]
11
     */
12
    protected $middleware = [];
13
14
    /**
15
     * {@inheritdoc}
16
     */
17 16
    public function middleware(MiddlewareInterface $middleware) : MiddlewareAwareInterface
18
    {
19 16
        $this->middleware[] = $middleware;
20
21 16
        return $this;
22
    }
23
24
    /**
25
     * {@inheritdoc}
26
     */
27 32
    public function middlewares(array $middlewares) : MiddlewareAwareInterface
28
    {
29 32
        foreach ($middlewares as $middleware) {
30 4
            $this->middleware($middleware);
31
        }
32
33 32
        return $this;
34
    }
35
36
    /**
37
     * {@inheritdoc}
38
     */
39 30
    public function prependMiddleware(MiddlewareInterface $middleware) : MiddlewareAwareInterface
40
    {
41 30
        array_unshift($this->middleware, $middleware);
42
43 30
        return $this;
44
    }
45
46
    /**
47
     * {@inheritdoc}
48
     */
49 30
    public function shiftMiddleware() : MiddlewareInterface
50
    {
51 30
        return array_shift($this->middleware);
52
    }
53
54
    /**
55
     * {@inheritdoc}
56
     */
57 32
    public function getMiddlewareStack() : iterable
58
    {
59 32
        return $this->middleware;
60
    }
61
}
62