GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( c4fd22...d26df2 )
by Hong
02:46
created

Event::setTarget()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
/**
3
 * Phossa Project
4
 *
5
 * PHP version 5.4
6
 *
7
 * @category  Library
8
 * @package   Phossa2\Event
9
 * @copyright Copyright (c) 2016 phossa.com
10
 * @license   http://mit-license.org/ MIT License
11
 * @link      http://www.phossa.com/
12
 */
13
/*# declare(strict_types=1); */
14
15
namespace Phossa2\Event;
16
17
use Phossa2\Event\Message\Message;
18
use Phossa2\Shared\Base\ObjectAbstract;
19
use Phossa2\Event\Interfaces\EventInterface;
20
use Phossa2\Event\Interfaces\EventResultInterface;
21
use Phossa2\Event\Exception\InvalidArgumentException;
22
23
/**
24
 * Event
25
 *
26
 * Basic implementation of EventInterface with array access to parameters
27
 *
28
 * ```php
29
 * // create event
30
 * $evt = new Event(
31
 *     'login.attempt',         // event name
32
 *     $this,                   // event target
33
 *     ['username' => 'phossa'] // event parameters
34
 * );
35
 *
36
 * // get/set event parameter
37
 * if ('phossa' === $evt['username']) {
38
 *     $evt['username'] = 'phossa2';
39
 * }
40
 *
41
 * // stop event
42
 * $evt->stopPropagation();
43
 * ```
44
 *
45
 * @package Phossa2\Event
46
 * @author  Hong Zhang <[email protected]>
47
 * @see     ObjectAbstract
48
 * @see     EventInterface
49
 * @see     EventResultInterface
50
 * @see     \ArrayAccess
51
 * @version 2.0.0
52
 * @since   2.0.0 added
53
 * @since   2.1.0 using psr EventInterface now
54
 */
55
class Event extends ObjectAbstract implements EventInterface, EventResultInterface, \ArrayAccess
56
{
57
    /**
58
     * event name
59
     *
60
     * @var    string
61
     * @access protected
62
     */
63
    protected $name;
64
65
    /**
66
     * event target/context
67
     *
68
     * an object OR static class name (string)
69
     *
70
     * @var    object|string|null
71
     * @access protected
72
     */
73
    protected $target;
74
75
    /**
76
     * event parameters
77
     *
78
     * @var    array
79
     * @access protected
80
     */
81
    protected $parameters;
82
83
    /**
84
     * Results from the handlers
85
     *
86
     * @var    array
87
     * @access protected
88
     */
89
    protected $results = [];
90
91
    /**
92
     * stop propagation
93
     *
94
     * @var    bool
95
     * @access protected
96
     */
97
    protected $stopped = false;
98
99
    /**
100
     * Constructor
101
     *
102
     * @param  string $eventName event name
103
     * @param  string|object|null $target event context, object or classname
104
     * @param  array $parameters (optional) event parameters
105
     * @throws InvalidArgumentException if event name is invalid
106
     * @access public
107
     * @api
108
     */
109
    public function __construct(
110
        /*# string */ $eventName,
111
        $target = null,
112
        array $parameters = []
113
    ) {
114
        $this->setName($eventName);
115
        $this->setTarget($target);
116
        $this->setParams($parameters);
117
    }
118
119
    /**
120
     * {@inheritDoc}
121
     */
122
    public function getName()
123
    {
124
        return $this->name;
125
    }
126
127
    /**
128
     * {@inheritDoc}
129
     */
130
    public function getTarget()
131
    {
132
        return $this->target;
133
    }
134
135
    /**
136
     * {@inheritDoc}
137
     */
138
    public function getParams()
139
    {
140
        return $this->parameters;
141
    }
142
143
    /**
144
     * {@inheritDoc}
145
     */
146
    public function getParam($name)
147
    {
148
        if (isset($this->parameters[(string) $name])) {
149
            return $this->parameters[(string) $name];
150
        }
151
        return null;
152
    }
153
154
    /**
155
     * {@inheritDoc}
156
     */
157
    public function setName($name)
158
    {
159
        if (!is_string($name) || empty($name)) {
160
            throw new InvalidArgumentException(
161
                Message::get(Message::EVT_NAME_INVALID, $name),
162
                Message::EVT_NAME_INVALID
163
            );
164
        }
165
        $this->name = $name;
166
    }
167
168
    /**
169
     * {@inheritDoc}
170
     */
171
    public function setTarget($target)
172
    {
173
        $this->target = $target;
174
    }
175
176
    /**
177
     * {@inheritDoc}
178
     */
179
    public function setParams(array $params)
180
    {
181
        $this->parameters = $params;
182
    }
183
184
    /**
185
     * {@inheritDoc}
186
     */
187
    public function stopPropagation($flag)
188
    {
189
        $this->stopped = (bool) $flag;
190
    }
191
192
    /**
193
     * {@inheritDoc}
194
     */
195
    public function isPropagationStopped()
196
    {
197
        return $this->stopped;
198
    }
199
200
    /**
201
     * {@inheritDoc}
202
     */
203
    public function addResult($result)
204
    {
205
        $this->results[] = $result;
206
    }
207
208
    /**
209
     * {@inheritDoc}
210
     */
211
    public function getResults()/*# : array */
212
    {
213
        return $this->results;
214
    }
215
216
    /**
217
     * {@inheritDoc}
218
     */
219
    public function offsetExists($offset)/*# : bool */
220
    {
221
        return isset($this->parameters[$offset]);
222
    }
223
224
    /**
225
     * {@inheritDoc}
226
     */
227
    public function offsetGet($offset)
228
    {
229
        return $this->getParam($offset);
230
    }
231
232
    /**
233
     * {@inheritDoc}
234
     */
235
    public function offsetSet($offset, $value)
236
    {
237
        $this->parameters[$offset] = $value;
238
    }
239
240
    /**
241
     * {@inheritDoc}
242
     */
243
    public function offsetUnset($offset)
244
    {
245
        unset($this->parameters[$offset]);
246
    }
247
}
248