AddsMiddleware   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 4
eloc 11
c 2
b 0
f 0
dl 0
loc 31
ccs 12
cts 12
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A replaceMiddleware() 0 5 1
A getMiddleware() 0 3 1
A middleware() 0 11 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