Completed
Push — master ( 8801ad...e19554 )
by Alexpts
02:50
created

MiddlewaresTrait   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 0
dl 0
loc 27
ccs 0
cts 8
cp 0
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
    public function pushMiddleware(callable $middleware)
14
    {
15
        $this->middlewares[] = $middleware;
16
        return $this;
17
    }
18
19
    /**
20
     * @return \callable[]
21
     */
22
    public function getMiddlewares() : array
23
    {
24
        return $this->middlewares;
25
    }
26
27
    protected function invoke(RequestInterface $request)
28
    {
29
        $middleware = array_shift($this->middlewares);
30
        return $middleware(... [$request, $this]);
31
    }
32
33
}
34