Test Failed
Branch master (e46a7e)
by mcfog
02:27
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 Lit\Nimo\Traits;
6
7
use Interop\Http\Server\MiddlewareInterface;
8
use Lit\Nimo\Interfaces\RequestPredictionInterface;
9
use Lit\Nimo\MiddlewarePipe;
10
use Lit\Nimo\Middlewares\CatchMiddleware;
11
use Lit\Nimo\Middlewares\PredictionWrapperMiddleware;
12
13
trait MiddlewareTrait
14
{
15
    use AttachToRequestTrait;
16
17
    /**
18
     * append $middleware after this one, return the new $middlewareStack
19
     *
20
     * @param $middleware
21
     * @return MiddlewarePipe
22
     */
23
    public function append(MiddlewareInterface $middleware): MiddlewarePipe
24
    {
25
        $stack = new MiddlewarePipe();
26
27
        return $stack
28
            ->append($this)
29
            ->append($middleware);
30
    }
31
32
    /**
33
     * prepend $middleware before this one, return the new $middlewareStack
34
     *
35
     * @param $middleware
36
     * @return MiddlewarePipe
37
     */
38
    public function prepend(MiddlewareInterface $middleware): MiddlewarePipe
39
    {
40
        $stack = new MiddlewarePipe();
41
42
        return $stack
43
            ->prepend($this)
44
            ->prepend($middleware);
45
    }
46
47
    public function when(RequestPredictionInterface $requestPrediction): MiddlewareInterface
48
    {
49
        return new PredictionWrapperMiddleware($this, $requestPrediction);
50
    }
51
52
    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...
53
    {
54
        return new CatchMiddleware($this, $catcher, $catchClass);
55
    }
56
}
57