SerializableEvent::getAll()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 0
1
<?php
2
namespace Workana\AsyncJobs;
3
4
use Symfony\Component\EventDispatcher\Event;
5
6
/**
7
 * @author Carlos Frutos <[email protected]>
8
 */
9
class SerializableEvent extends Event
10
{
11
    /**
12
     * @var array
13
     */
14
    protected $parameters = [];
15
16
    /**
17
     * @param string $name
18
     * @param mixed $value
19
     */
20
    public function set($name, $value)
21
    {
22
        $this->parameters[(string) $name] = new Parameter($value, $name);
23
    }
24
25
    /**
26
     * @param string $name
27
     * @param mixed $default
28
     *
29
     * @return mixed
30
     */
31
    public function get($name, $default = null)
32
    {
33
        if (isset($this->parameters[$name])) {
34
            return $this->parameters[$name]->getValue();
35
        } else {
36
            return $default;
37
        }
38
    }
39
40
    /**
41
     * @param string $name
42
     *
43
     * @return bool
44
     */
45
    public function has($name)
46
    {
47
        return array_key_exists($name, $this->parameters);
48
    }
49
50
    /**
51
     * Get all parameters
52
     *
53
     * @return array
54
     */
55
    public function getAll()
56
    {
57
        $result = [];
58
59
        foreach ($this->parameters as $name => $parameter) {
60
            $result[$name] = $parameter->getValue();
61
        }
62
63
        return $result;
64
    }
65
}