AbstractRouteEvent::getParams()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Webino™ (http://webino.sk)
4
 *
5
 * @link        https://github.com/webino for the canonical source repository
6
 * @copyright   Copyright (c) 2015-2017 Webino, s.r.o. (http://webino.sk)
7
 * @author      Peter Bačinský <[email protected]>
8
 * @license     BSD-3-Clause
9
 */
10
11
namespace WebinoAppLib\Event;
12
13
use Zend\Mvc\Router\RouteMatch;
14
15
/**
16
 * Class AbstractRouteEvent
17
 */
18
abstract class AbstractRouteEvent extends DispatchEvent implements
19
    RouteEventInterface
20
{
21
    /**
22
     * Route match param name
23
     */
24
    const ROUTE_MATCH = 'routeMatch';
25
26
    /**
27
     * @var DispatchEvent
28
     */
29
    private $parentEvent;
30
31
    /**
32
     * @param DispatchEvent $event
33
     */
34
    public function __construct(DispatchEvent $event)
35
    {
36
        $this->parentEvent = $event;
37
        parent::__construct($event->getApp());
0 ignored issues
show
Documentation introduced by
$event->getApp() is of type object<WebinoAppLib\Appl...on\AbstractApplication>, but the function expects a object<WebinoAppLib\Appl...edApplicationInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
38
        $this->setName($this::MATCH);
39
        $this->setRequest($event->getRequest());
40
    }
41
42
    /**
43
     * {@inheritdoc}
44
     */
45
    public function getResponse()
46
    {
47
        return $this->parentEvent->getResponse();
48
    }
49
50
    /**
51
     * {@inheritdoc}
52
     */
53
    public function setResponse($response)
54
    {
55
        $this->parentEvent->setResponse($response);
56
        return $this;
57
    }
58
59
    /**
60
     * Get a specific parameter
61
     *
62
     * @param string $name
63
     * @param mixed $default
64
     * @return mixed
65
     */
66
    public function getParam($name, $default = null)
67
    {
68
        return $this->getRouteMatch()->getParam($name, $default);
69
    }
70
71
    /**
72
     * Set value to a parameter
73
     *
74
     * @param  string|int $name
75
     * @param  mixed $value
76
     * @return $this
77
     */
78
    public function setParam($name, $value)
79
    {
80
        $this->getRouteMatch()->setParam($name, $value);
81
        return $this;
82
    }
83
84
    /**
85
     * Get all parameters
86
     *
87
     * @return array|object|\ArrayAccess
88
     */
89
    public function getParams()
90
    {
91
        return $this->getRouteMatch()->getParams();
92
    }
93
94
    /**
95
     * Set parameters
96
     *
97
     * Overwrites parameters
98
     *
99
     * @param  array|\ArrayAccess|object $params
100
     * @return $this
101
     * @throws \Zend\EventManager\Exception\InvalidArgumentException
102
     */
103
    public function setParams($params)
104
    {
105
        foreach ($params as $name => $value) {
106
            $this->setParam($name, $value);
107
        };
108
        return $this;
109
    }
110
111
    /**
112
     * @return \Zend\Mvc\Router\Http\RouteMatch
113
     */
114
    public function getRouteMatch()
115
    {
116
        $routeMatch = $this->getEventParam($this::ROUTE_MATCH);
117
        if (null === $routeMatch) {
118
            // null object by default
119
            $routeMatch = new RouteMatch([]);
120
            $this->setEventParam($this::ROUTE_MATCH, $routeMatch);
121
        }
122
        return $routeMatch;
123
    }
124
}
125