Passed
Push — master ( 2aa8dd...218721 )
by n
03:53
created

RoutingResult::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 11
c 0
b 0
f 0
ccs 6
cts 6
cp 1
rs 9.4285
cc 1
eloc 9
nc 1
nop 4
crap 1
1
<?php
2
declare(strict_types=1);
3
4
namespace N1215\Http\Router;
5
6
use Interop\Http\Server\RequestHandlerInterface;
7
8
final class RoutingResult implements RoutingResultInterface
9
{
10
    /** @var bool  */
11
    private $isSuccess;
12
13
    /** @var RequestHandlerInterface|null  */
14
    private $matchedHandler;
15
16
    /** @var array  */
17
    private $matchedParams;
18
19
    /** @var RoutingErrorInterface|null  */
20
    private $error;
21
22 4
    private function __construct(
23
        bool $isSuccess,
24
        ?RequestHandlerInterface $matchedHandler = null,
25
        array $matchedParams = [],
26
        ?RoutingErrorInterface $error = null
27
    ) {
28 4
        $this->isSuccess = $isSuccess;
29 4
        $this->matchedHandler = $matchedHandler;
30 4
        $this->matchedParams = $matchedParams;
31 4
        $this->error = $error;
32 4
    }
33
34 4
    public function isSuccess(): bool
35
    {
36 4
        return $this->isSuccess;
37
    }
38
39 3
    public function getMatchedHandler(): ?RequestHandlerInterface
40
    {
41 3
        return $this->matchedHandler;
42
    }
43
44 3
    public function getMatchedParams(): array
45
    {
46 3
        return $this->matchedParams;
47
    }
48
49 3
    public function getError(): ?RoutingErrorInterface
50
    {
51 3
        return $this->error;
52
    }
53
54 2
    public static function success(RequestHandlerInterface $matchedHandler, array $matchedParams): self
55
    {
56 2
        return new self(true, $matchedHandler, $matchedParams);
57
    }
58
59 2
    public static function failure(RoutingErrorInterface $error): self
60
    {
61 2
        return new self(false, null, [], $error);
62
    }
63
}
64