Passed
Push — master ( b51215...92fe06 )
by Alexander
01:26
created

MatchingResult   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 10
eloc 21
c 2
b 0
f 0
dl 0
loc 55
ccs 23
cts 23
cp 1
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A isSuccess() 0 3 1
A fromSuccess() 0 7 1
A methods() 0 3 1
A fromFailure() 0 6 1
A parameters() 0 3 1
A process() 0 7 2
A isMethodFailure() 0 3 2
A __construct() 0 2 1
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
use Yiisoft\Http\Method;
10
11
final class MatchingResult implements MiddlewareInterface
12
{
13
    private bool $success;
14
    private Route $route;
15
    private array $parameters = [];
16
    private array $methods = [];
17
18
    private function __construct()
19
    {
20
    }
21
22 3
    public static function fromSuccess(Route $route, array $parameters): self
23
    {
24 3
        $new = new self();
25 3
        $new->success = true;
26 3
        $new->route = $route;
27 3
        $new->parameters = $parameters;
28 3
        return $new;
29
    }
30
31 5
    public static function fromFailure(array $methods): self
32
    {
33 5
        $new = new self();
34 5
        $new->methods = $methods;
35 5
        $new->success = false;
36 5
        return $new;
37
    }
38
39 5
    public function isSuccess(): bool
40
    {
41 5
        return $this->success;
42
    }
43
44 5
    public function isMethodFailure(): bool
45
    {
46 5
        return !$this->success && $this->methods !== Method::ANY;
47
    }
48
49 2
    public function parameters(): array
50
    {
51 2
        return $this->parameters;
52
    }
53
54 2
    public function methods(): array
55
    {
56 2
        return $this->methods;
57
    }
58
59 3
    public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
60
    {
61 3
        if ($this->success === false) {
62 1
            return $handler->handle($request);
63
        }
64
65 2
        return $this->route->process($request, $handler);
66
    }
67
}
68