RouteMatch::remove()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 3
nc 1
nop 1
crap 1
1
<?php
2
3
  namespace ReRoute;
4
5
  use ReRoute\Route\AbstractRoute;
6
7
8
  /**
9
   *
10
   * @package ReRoute
11
   */
12
  class RouteMatch {
13
14
15
    /**
16
     * @var mixed
17
     */
18
    private $routeResult = null;
19
20
21
    /**
22
     * @var array
23
     */
24
    private $parameters = [];
25
26
27
    /**
28
     * @param $routeResult
29
     */
30 45
    public function __construct($routeResult) {
31 45
      if (!is_string($routeResult)) {
32
        throw new \InvalidArgumentException('Invalid result type. Expect string. Given "' . gettype($routeResult) . '"');
33
      }
34 45
      $this->routeResult = $routeResult;
35 45
    }
36
37
38
    /**
39
     * @return mixed
40
     */
41 9
    public function getRouteResult() {
42 9
      return $this->routeResult;
43
    }
44
45
46
    /**
47
     * Checks if a parameter value is set for the given parameter.
48
     *
49
     * @param string $name A parameter name
50
     *
51
     * @return bool True if the parameter value is set, false otherwise
52
     */
53 3
    public function has($name) {
54 3
      return array_key_exists($name, $this->parameters);
55
    }
56
57
58
    /**
59
     * Removes a parameter
60
     *
61
     * @param string $name
62
     *
63
     * @return $this
64
     */
65 3
    public function remove($name) {
66 3
      unset($this->parameters[$name]);
67 3
      return $this;
68
    }
69
70
71
    /**
72
     * @return array
73
     */
74
    public function getParameters() {
75
      return $this->parameters;
76
    }
77
78
79
    /**
80
     * @param string $field
81
     * @param mixed $value
82
     * @return $this
83
     */
84 30
    public function set($field, $value) {
85 30
      $this->parameters[$field] = $value;
86 30
      return $this;
87
    }
88
89
90
    /**
91
     * Gets a parameter value.
92
     *
93
     * @param string $name A parameter name
94
     *
95
     * @return mixed The parameter value or null if nonexistent
96
     */
97 15
    public function get($name) {
98 15
      return isset($this->parameters[$name]) ? $this->parameters[$name] : null;
99
    }
100
101
  }