RequestRoute   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 2
dl 0
loc 61
ccs 16
cts 16
cp 1
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getRoute() 0 3 1
A getParameters() 0 3 1
A getParameter() 0 9 2
A hasParameter() 0 4 1
1
<?php
2
3
/*
4
 * Copyright (c) 2011-2015, Celestino Diaz <[email protected]>
5
 *
6
 * Permission is hereby granted, free of charge, to any person obtaining a copy
7
 * of this software and associated documentation files (the "Software"), to deal
8
 * in the Software without restriction, including without limitation the rights
9
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
 * copies of the Software, and to permit persons to whom the Software is
11
 * furnished to do so, subject to the following conditions:
12
 *
13
 * The above copyright notice and this permission notice shall be included in
14
 * all copies or substantial portions of the Software.
15
 *
16
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
 * THE SOFTWARE.
23
 */
24
25
namespace Brickoo\Component\Routing\Route;
26
27
use Brickoo\Component\Routing\Route\Exception\ParameterNotAvailableException;
28
use Brickoo\Component\Common\Assert;
29
30
/**
31
 * RequestRoute
32
 *
33
 * Implementation of an executable route containing the responsible route.
34
 * @author Celestino Diaz <[email protected]>
35
 */
36
class RequestRoute {
37
38
    /** @var \Brickoo\Component\Routing\Route\Route */
39
    private $route;
40
41
    /** @var array */
42
    private $parameters;
43
44
    /**
45
     * Class constructor.
46
     * @param \Brickoo\Component\Routing\Route\Route $route the matching request route
47
     * @param array $parameters the parameters extracted from the request
48
     */
49 1
    public function __construct(Route $route, array $parameters = []) {
50 1
        $this->route = $route;
51 1
        $this->parameters = $parameters;
52 1
    }
53
54
    /**
55
     * Return the matched route.
56
     * @return \Brickoo\Component\Routing\Route\Route
57
     */
58 1
    public function getRoute() {
59 1
        return $this->route;
60
    }
61
62
    /**
63
     * Return the route parameters and values as pairs.
64
     * @return array the route parameters and values
65
     */
66 1
    public function getParameters() {
67 1
        return $this->parameters;
68
    }
69
70
    /**
71
     * Return the value of the parameter.
72
     * @param string $parameter the parameter name
73
     * @throws \Brickoo\Component\Routing\Route\Exception\ParameterNotAvailableException
74
     * @return string the parameter value
75
     */
76 3
    public function getParameter($parameter) {
77 3
        Assert::isString($parameter);
78
79 2
        if (!$this->hasParameter($parameter)) {
80 1
            throw new ParameterNotAvailableException($parameter);
81
        }
82
83 1
        return $this->parameters[$parameter];
84
    }
85
86
    /**
87
     * Check if the parameter is available.
88
     * @param string $parameter the parameter name
89
     * @return boolean check result
90
     */
91 2
    public function hasParameter($parameter) {
92 2
        Assert::isString($parameter);
93 1
        return isset($this->parameters[$parameter]);
94
    }
95
96
}
97