Passed
Branch master (701f59)
by Alexpts
02:08
created

MiddlewaresTrait   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A pushMiddleware() 0 5 1
A getMiddlewares() 0 4 1
A invoke() 0 5 1
1
<?php
2
declare(strict_types = 1);
3
namespace PTS\Routing\Traits;
4
5
use Psr\Http\Message\RequestInterface;
6
7
trait MiddlewaresTrait
8
{
9
    /** @var callable[] */
10
    protected $middlewares = [];
11
12
13 10
    public function pushMiddleware(callable $middleware)
14
    {
15 10
        $this->middlewares[] = $middleware;
16 10
        return $this;
17
    }
18
19
    /**
20
     * @return \callable[]
21
     */
22 11
    public function getMiddlewares() : array
23
    {
24 11
        return $this->middlewares;
25
    }
26
27 10
    protected function invoke(RequestInterface $request)
28
    {
29 10
        $middleware = array_shift($this->middlewares);
30 10
        return $middleware(... [$request, $this]);
31
    }
32
33
}
34