Passed
Push — master ( 68c311...b75818 )
by Alexander
11:49
created

MatchingResult   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 8
eloc 20
c 2
b 0
f 0
dl 0
loc 54
rs 10

7 Methods

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