AddsMiddleware::middleware()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
dl 0
loc 11
ccs 7
cts 7
cp 1
rs 10
c 1
b 0
f 0
cc 2
nc 1
nop 1
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Conia\Chuck\Routing;
6
7
use Closure;
8
use Conia\Chuck\Middleware;
9
use Psr\Http\Server\MiddlewareInterface as PsrMiddleware;
10
11
trait AddsMiddleware
12
{
13
    /** @var list<list{non-falsy-string, ...}|Closure|Middleware|PsrMiddleware> */
0 ignored issues
show
Bug introduced by
The type Conia\Chuck\Routing\list was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
14
    protected array $middleware = [];
15
16
    /** @psalm-param non-falsy-string|list{non-falsy-string, ...}|Closure|Middleware|PsrMiddleware ...$middleware */
17 44
    public function middleware(string|array|Closure|Middleware|PsrMiddleware ...$middleware): static
18
    {
19 44
        $this->middleware = array_merge($this->middleware, array_map(function ($mw) {
0 ignored issues
show
Documentation Bug introduced by
It seems like array_merge($this->middl...y_values($middleware))) of type array is incompatible with the declared type Conia\Chuck\Routing\list of property $middleware.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
20 34
            if (is_string($mw)) {
21 9
                return [$mw];
22
            }
23
24 30
            return $mw;
25 44
        }, array_values($middleware)));
26
27 44
        return $this;
28
    }
29
30
    /** @psalm-return list<list{non-falsy-string, ...}|Closure|Middleware|PsrMiddleware> */
31 30
    public function getMiddleware(): array
32
    {
33 30
        return $this->middleware;
34
    }
35
36
    /** @psalm-param list<list{non-falsy-string, ...}|Closure|Middleware|PsrMiddleware> $middleware */
37 2
    public function replaceMiddleware(array $middleware): static
38
    {
39 2
        $this->middleware = $middleware;
0 ignored issues
show
Documentation Bug introduced by
It seems like $middleware of type array is incompatible with the declared type Conia\Chuck\Routing\list of property $middleware.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
40
41 2
        return $this;
42
    }
43
}
44