Passed
Push — master ( a071d4...32677b )
by Felipe
02:03
created

RouteMatch   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 8
dl 0
loc 45
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getHandler() 0 3 1
A getVariables() 0 3 2
A isSuccess() 0 3 1
A __construct() 0 4 1
1
<?php declare(strict_types=1);
2
/*
3
 * This file is part of coisa/http.
4
 *
5
 * (c) Felipe Sayão Lobato Abreu <[email protected]>
6
 *
7
 * This source file is subject to the license that is bundled
8
 * with this source code in the file LICENSE.
9
 */
10
11
namespace CoiSA\Http;
12
13
use Psr\Http\Server\RequestHandlerInterface;
14
15
/**
16
 * Interface RouterInterface
17
 *
18
 * @package CoiSA\Http
19
 */
20
final class RouteMatch implements RouteMatchInterface
21
{
22
    /**
23
     * @var RequestHandlerInterface
24
     */
25
    private $handler;
26
27
    /**
28
     * @var array|null
29
     */
30
    private $matches;
31
32
    /**
33
     * Router constructor.
34
     *
35
     * @param RequestHandlerInterface $notFoundHandler
36
     */
37
    public function __construct(RequestHandlerInterface $handler, ?array $matches = null)
38
    {
39
        $this->handler = $handler;
40
        $this->matches = $matches;
41
    }
42
43
    /**
44
     * @return bool
45
     */
46
    public function isSuccess(): bool
47
    {
48
        return !empty($this->matches);
49
    }
50
51
    /**
52
     * @return RequestHandlerInterface
53
     */
54
    public function getHandler(): RequestHandlerInterface
55
    {
56
        return $this->handler;
57
    }
58
59
    /**
60
     * @return array
61
     */
62
    public function getVariables(): array
63
    {
64
        return is_array($this->matches) ? $this->matches : [];
65
    }
66
}
67