Passed
Push — master ( ae5e1d...1278d9 )
by mcfog
02:02
created

MiddlewareTrait::when()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Nimo\Traits;
6
7
use Interop\Http\Server\MiddlewareInterface;
8
use Nimo\MiddlewarePipe;
9
use Nimo\Middlewares\CatchMiddleware;
10
11
trait MiddlewareTrait
12
{
13
    use AttachToRequestTrait;
14
15
    /**
16
     * append $middleware after this one, return the new $middlewareStack
17
     *
18
     * @param $middleware
19
     * @return MiddlewarePipe
20
     */
21
    public function append(MiddlewareInterface $middleware): MiddlewarePipe
22
    {
23
        $stack = new MiddlewarePipe();
24
25
        return $stack
26
            ->append($this)
27
            ->append($middleware);
28
    }
29
30
    /**
31
     * prepend $middleware before this one, return the new $middlewareStack
32
     *
33
     * @param $middleware
34
     * @return MiddlewarePipe
35
     */
36
    public function prepend(MiddlewareInterface $middleware): MiddlewarePipe
37
    {
38
        $stack = new MiddlewarePipe();
39
40
        return $stack
41
            ->prepend($this)
42
            ->prepend($middleware);
43
    }
44
45
    public function catch(callable $catcher, string $catchClass = \Throwable::class): MiddlewareInterface
0 ignored issues
show
Coding Style introduced by
Possible parse error: non-abstract method defined as abstract
Loading history...
Coding Style introduced by
It is generally advisable to only define one property per statement.

Only declaring a single property per statement allows you to later on add doc comments more easily.

It is also recommended by PSR2, so it is a common style that many people expect.

Loading history...
46
    {
47
        return new CatchMiddleware($this, $catcher, $catchClass);
48
    }
49
}
50