Passed
Push — master ( 7f4b2c...233608 )
by mcfog
02:50
created

MiddlewareCompositeTrait::when()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 4
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Lit\Nimo\Traits;
6
7
use Lit\Nimo\Interfaces\RequestPredictionInterface;
8
use Lit\Nimo\MiddlewarePipe;
9
use Lit\Nimo\Middlewares\CatchMiddleware;
10
use Lit\Nimo\Middlewares\PredictionWrapperMiddleware;
11
use Psr\Http\Server\MiddlewareInterface;
12
13
trait MiddlewareCompositeTrait
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
        /** @noinspection PhpParamsInspection */
26
        return $stack
27
            ->append($this)
0 ignored issues
show
Bug introduced by
$this of type Lit\Nimo\Traits\MiddlewareCompositeTrait is incompatible with the type Psr\Http\Server\MiddlewareInterface expected by parameter $middleware of Lit\Nimo\MiddlewarePipe::append(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

27
            ->append(/** @scrutinizer ignore-type */ $this)
Loading history...
28
            ->append($middleware);
29
    }
30
31
    /**
32
     * prepend $middleware before this one, return the new $middlewareStack
33
     *
34
     * @param $middleware
35
     * @return MiddlewarePipe
36
     */
37
    public function prepend(MiddlewareInterface $middleware): MiddlewarePipe
38
    {
39
        $stack = new MiddlewarePipe();
40
41
        /** @noinspection PhpParamsInspection */
42
        return $stack
43
            ->prepend($this)
0 ignored issues
show
Bug introduced by
$this of type Lit\Nimo\Traits\MiddlewareCompositeTrait is incompatible with the type Psr\Http\Server\MiddlewareInterface expected by parameter $middleware of Lit\Nimo\MiddlewarePipe::prepend(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

43
            ->prepend(/** @scrutinizer ignore-type */ $this)
Loading history...
44
            ->prepend($middleware);
45
    }
46
47
    public function when(RequestPredictionInterface $requestPrediction): MiddlewareInterface
48
    {
49
        /** @noinspection PhpParamsInspection */
50
        return new PredictionWrapperMiddleware($this, $requestPrediction);
0 ignored issues
show
Bug introduced by
$this of type Lit\Nimo\Traits\MiddlewareCompositeTrait is incompatible with the type Psr\Http\Server\MiddlewareInterface expected by parameter $innerMiddleware of Lit\Nimo\Middlewares\Pre...ddleware::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

50
        return new PredictionWrapperMiddleware(/** @scrutinizer ignore-type */ $this, $requestPrediction);
Loading history...
51
    }
52
53
    public function unless(RequestPredictionInterface $requestPrediction): MiddlewareInterface
54
    {
55
        /** @noinspection PhpParamsInspection */
56
        return new PredictionWrapperMiddleware($this, $requestPrediction, true);
0 ignored issues
show
Bug introduced by
$this of type Lit\Nimo\Traits\MiddlewareCompositeTrait is incompatible with the type Psr\Http\Server\MiddlewareInterface expected by parameter $innerMiddleware of Lit\Nimo\Middlewares\Pre...ddleware::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

56
        return new PredictionWrapperMiddleware(/** @scrutinizer ignore-type */ $this, $requestPrediction, true);
Loading history...
57
    }
58
59 1
    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...
60
    {
61 1
        return new CatchMiddleware($this, $catcher, $catchClass);
62
    }
63
}
64