Passed
Pull Request — master (#196)
by Rustam
02:35
created

MatchingResult   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 16
c 2
b 0
f 0
dl 0
loc 75
ccs 22
cts 22
cp 1
rs 10
wmc 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A isSuccess() 0 3 1
A isMethodFailure() 0 3 2
A fromSuccess() 0 5 1
A methods() 0 3 1
A fromFailure() 0 5 1
A route() 0 7 2
A arguments() 0 3 1
A __construct() 0 2 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Router;
6
7
use RuntimeException;
8
use Yiisoft\Http\Method;
9
10
final class MatchingResult
11
{
12
    /**
13
     * @var array<string,string>
14
     */
15
    private array $arguments = [];
16
17
    /**
18
     * @var string[]
19
     */
20
    private array $methods = [];
21
22 18
    private function __construct(private ?Route $route)
23
    {
24 18
    }
25
26
    /**
27
     * @param array<string,string> $arguments
28
     */
29 11
    public static function fromSuccess(Route $route, array $arguments): self
30
    {
31 11
        $new = new self($route);
32 11
        $new->arguments = $arguments;
33 11
        return $new;
34
    }
35
36
    /**
37
     * @param string[] $methods
38
     */
39 7
    public static function fromFailure(array $methods): self
40
    {
41 7
        $new = new self(null);
42 7
        $new->methods = $methods;
43 7
        return $new;
44
    }
45
46
    /**
47
     * @psalm-assert-if-true !null $this->route
48
     */
49 14
    public function isSuccess(): bool
50
    {
51 14
        return $this->route !== null;
52
    }
53
54 16
    public function isMethodFailure(): bool
55
    {
56 16
        return $this->route === null && $this->methods !== Method::ALL;
57
    }
58
59
    /**
60
     * @return array<string,string>
61
     */
62 11
    public function arguments(): array
63
    {
64 11
        return $this->arguments;
65
    }
66
67
    /**
68
     * @return string[]
69
     */
70 4
    public function methods(): array
71
    {
72 4
        return $this->methods;
73
    }
74
75
    /**
76
     * @psalm-assert-if-true !null $this->route
77
     */
78 11
    public function route(): Route
79
    {
80 11
        if ($this->route === null) {
81 1
            throw new RuntimeException('There is no route in the matching result.');
82
        }
83
84 10
        return $this->route;
85
    }
86
}
87