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

FallbackMatcher   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
c 1
b 0
f 0
dl 0
loc 32
ccs 0
cts 11
cp 0
rs 10
wmc 7

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getCurrentRoute() 0 3 2
A match() 0 10 2
A getCurrentUri() 0 3 2
A __construct() 0 3 1
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