Passed
Push — master ( f908b9...b51215 )
by Alexander
01:21
created

MatchingResult::process()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.0625

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 7
ccs 3
cts 4
cp 0.75
rs 10
cc 2
nc 2
nop 2
crap 2.0625
1
<?php
2
3
namespace Yiisoft\Router;
4
5
use Psr\Http\Message\ResponseInterface;
6
use Psr\Http\Message\ServerRequestInterface;
7
use Psr\Http\Server\MiddlewareInterface;
8
use Psr\Http\Server\RequestHandlerInterface;
9
10
final class MatchingResult implements MiddlewareInterface
11
{
12
    private bool $success;
13
    private Route $route;
14
    private array $parameters = [];
15
    private array $methods = [];
16
17
    private function __construct()
18
    {
19
    }
20
21
    public static function fromSuccess(Route $route, array $parameters): self
22
    {
23
        $new = new self();
24
        $new->success = true;
25
        $new->route = $route;
26
        $new->parameters = $parameters;
27
        return $new;
28
    }
29
30 3
    public static function fromFailure(array $methods): self
31
    {
32 3
        $new = new self();
33 3
        $new->methods = $methods;
34 3
        $new->success = false;
35 3
        return $new;
36
    }
37
38 2
    public function isSuccess(): bool
39
    {
40 2
        return $this->success;
41
    }
42
43 2
    public function isMethodFailure(): bool
44
    {
45 2
        return !$this->success && $this->methods !== Method::ANY;
0 ignored issues
show
Bug introduced by
The type Yiisoft\Router\Method 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...
46
    }
47
48
    public function parameters(): array
49
    {
50
        return $this->parameters;
51
    }
52
53
    public function methods(): array
54
    {
55
        return $this->methods;
56
    }
57
58 1
    public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
59
    {
60 1
        if ($this->success === false) {
61 1
            return $handler->handle($request);
62
        }
63
64
        return $this->route->process($request, $handler);
65
    }
66
}
67