Passed
Pull Request — master (#91)
by Alexander
07:39
created

FallbackMatcher::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
6
namespace Yiisoft\Router;
7
8
9
use Psr\Http\Message\ServerRequestInterface;
10
use Psr\Http\Message\UriInterface;
11
12
class FallbackMatcher implements UrlMatcherInterface
13
{
14
    private UrlMatcherInterface $urlMatcher;
15
    private ?Route $currentRoute = null;
16
    private ?UriInterface $currentUri = null;
17
    private bool $isFallback = false;
18
19
    public function __construct(UrlMatcherInterface $urlMatcher)
20
    {
21
        $this->urlMatcher = $urlMatcher;
22
    }
23
24
    public function match(ServerRequestInterface $request): MatchingResult
25
    {
26
        $result = $this->urlMatcher->match($request);
27
        if (!$result->isSuccess()) {
28
            $this->isFallback = true;
29
            // fallback match
30
            // $this->currentRoute = ...
31
            // $this->currentUrl = ...
32
        }
33
        return $result;
34
    }
35
36
    public function getCurrentRoute(): ?Route
37
    {
38
        return $this->isFallback ? $this->currentRoute : $this->urlMatcher->getCurrentRoute();
39
    }
40
41
    public function getCurrentUri(): ?UriInterface
42
    {
43
        return $this->isFallback ? $this->currentUri : $this->urlMatcher->getCurrentUri();
44
    }
45
}
46