Passed
Pull Request — master (#225)
by Rustam
02:46
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 route() 0 7 2
A isSuccess() 0 3 1
A fromSuccess() 0 5 1
A methods() 0 3 1
A fromFailure() 0 5 1
A arguments() 0 3 1
A isMethodFailure() 0 3 2
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 string[]
14
     * @psalm-var array<string,string>
15
     */
16
    private array $arguments = [];
17
18
    /**
19
     * @var string[]
20
     */
21
    private array $methods = [];
22
23 18
    private function __construct(private ?Route $route)
24
    {
25 18
    }
26
27
    /**
28
     * @param string[] $arguments
29
     * @psalm-param array<string,string> $arguments
30
     */
31 11
    public static function fromSuccess(Route $route, array $arguments): self
32
    {
33 11
        $new = new self($route);
34 11
        $new->arguments = $arguments;
35 11
        return $new;
36
    }
37
38
    /**
39
     * @param string[] $methods
40
     */
41 7
    public static function fromFailure(array $methods): self
42
    {
43 7
        $new = new self(null);
44 7
        $new->methods = $methods;
45 7
        return $new;
46
    }
47
48
    /**
49
     * @psalm-assert-if-true !null $this->route
50
     */
51 14
    public function isSuccess(): bool
52
    {
53 14
        return $this->route !== null;
54
    }
55
56 16
    public function isMethodFailure(): bool
57
    {
58 16
        return $this->route === null && $this->methods !== Method::ALL;
59
    }
60
61
    /**
62
     * @return string[]
63
     * @psalm-return array<string,string>
64
     */
65 11
    public function arguments(): array
66
    {
67 11
        return $this->arguments;
68
    }
69
70
    /**
71
     * @return string[]
72
     */
73 4
    public function methods(): array
74
    {
75 4
        return $this->methods;
76
    }
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