Parsed::getParameters()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Kambo\Router\Route\Route;
5
6
use Kambo\Router\Route\Route;
7
8
/**
9
 * Parsed route from matcher class.
10
 * Class is implemented as a proxy for existing Route object.
11
 *
12
 * @package Kambo\Router\Route\Route
13
 * @author  Bohuslav Simek <[email protected]>
14
 * @license MIT
15
 */
16
class Parsed
17
{
18
    /**
19
     * Instance of original route
20
     *
21
     * @var \Kambo\Router\Route\Route
22
     */
23
    private $route;
24
25
    /**
26
     * Route placeholders from route.
27
     *
28
     * @var array
29
     */
30
    private $placeholders;
31
32
    /**
33
     * Route parameters from request
34
     *
35
     * @var array
36
     */
37
    private $parameters;
38
39
    /**
40
     * ParsedRoute constructor
41
     *
42
     * @param \Kambo\Router\Route\Route $route Existing route which will be used as a base for proxy.
43
     */
44 39
    public function __construct(Route $route)
45
    {
46 39
        $this->route = $route;
47 39
    }
48
49
    /**
50
     * Magic method for proxing methods call to parent route.
51
     *
52
     * @param string $name      Method name
53
     * @param array  $arguments The parameters to be passed to the method,
54
     *                          as an indexed array.
55
     *
56
     * @return mixed
57
     */
58 1
    public function __call(string $name, array $arguments)
59
    {
60 1
        return call_user_func_array([$this->route, $name], $arguments);
61
    }
62
63
    /**
64
     * Get route method
65
     *
66
     * @return string
67
     */
68 31
    public function getMethod() : string
69
    {
70 31
        return $this->route->getMethod();
71
    }
72
73
    /**
74
     * Get handler
75
     *
76
     * @return mixed
77
     */
78 16
    public function getHandler()
79
    {
80 16
        return $this->route->getHandler();
81
    }
82
83
    /**
84
     * Sets placeholders extracted from route.
85
     *
86
     * @param arrat $placeholders
87
     *
88
     * @return self for fluent interface
89
     */
90 37
    public function setPlaceholders(array $placeholders) : Parsed
91
    {
92 37
        $this->placeholders = $placeholders;
93
94 37
        return $this;
95
    }
96
97
    /**
98
     * Get placeholders extracted from route.
99
     *
100
     * @return array
101
     */
102 16
    public function getPlaceholders() : array
103
    {
104 16
        return $this->placeholders;
105
    }
106
107
    /**
108
     * Sets parameters for route from request.
109
     *
110
     * @param mixed $parameters
111
     *
112
     * @return self for fluent interface
113
     */
114 32
    public function setParameters(array $parameters) : Parsed
115
    {
116 32
        $this->parameters = $parameters;
117
118 32
        return $this;
119
    }
120
121
    /**
122
     * Get parameters of route from request.
123
     *
124
     * @return array
125
     */
126 28
    public function getParameters() : array
127
    {
128 28
        return $this->parameters;
129
    }
130
}
131