Passed
Pull Request — master (#91)
by Alexander
09:37 queued 07:29
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
namespace Yiisoft\Router;
6
7
use Psr\Http\Message\ServerRequestInterface;
8
use Psr\Http\Message\UriInterface;
9
10
class FallbackMatcher implements UrlMatcherInterface
11
{
12
    private UrlMatcherInterface $urlMatcher;
13
    private ?Route $currentRoute = null;
14
    private ?UriInterface $currentUri = null;
15
    private bool $isFallback = false;
16
17
    public function __construct(UrlMatcherInterface $urlMatcher)
18
    {
19
        $this->urlMatcher = $urlMatcher;
20
    }
21
22
    public function match(ServerRequestInterface $request): MatchingResult
23
    {
24
        $result = $this->urlMatcher->match($request);
25
        if (!$result->isSuccess()) {
26
            $this->isFallback = true;
27
            // fallback match
28
            // $this->currentRoute = ...
29
            // $this->currentUrl = ...
30
        }
31
        return $result;
32
    }
33
34
    public function getCurrentRoute(): ?Route
35
    {
36
        return $this->isFallback ? $this->currentRoute : $this->urlMatcher->getCurrentRoute();
37
    }
38
39
    public function getCurrentUri(): ?UriInterface
40
    {
41
        return $this->isFallback ? $this->currentUri : $this->urlMatcher->getCurrentUri();
42
    }
43
}
44