InMemoryEvent   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 76
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 7
c 3
b 0
f 0
lcom 0
cbo 0
dl 0
loc 76
ccs 0
cts 22
cp 0
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A serialize() 0 7 1
A unserialize() 0 15 3
A getName() 0 4 1
A getParameters() 0 4 1
1
<?php
2
3
namespace AsyncPHP\Remit\Event;
4
5
use AsyncPHP\Remit\Event;
6
use InvalidArgumentException;
7
8
final class InMemoryEvent implements Event
9
{
10
    /**
11
     * @var string
12
     */
13
    private $name;
14
15
    /**
16
     * @var array
17
     */
18
    private $parameters = [];
19
20
    /**
21
     * @param string $name
22
     * @param array $parameters
23
     */
24
    public function __construct($name, array $parameters = [])
25
    {
26
        $this->name = $name;
27
        $this->parameters = $parameters;
28
    }
29
30
    /**
31
     * @inheritdoc
32
     *
33
     * @return string
34
     */
35
    public function serialize()
36
    {
37
        return serialize([
38
            "name" => $this->name,
39
            "parameters" => $this->parameters,
40
        ]);
41
    }
42
43
    /**
44
     * @inheritdoc
45
     *
46
     * @param string $serialized
47
     */
48
    public function unserialize($serialized)
49
    {
50
        $data = unserialize($serialized);
51
52
        if (!isset($data["name"])) {
53
            throw new InvalidArgumentException("malformed event");
54
        }
55
56
        if (!isset($data["parameters"])) {
57
            throw new InvalidArgumentException("malformed event");
58
        }
59
60
        $this->name = $data["name"];
61
        $this->parameters = $data["parameters"];
62
    }
63
64
    /**
65
     * @inheritdoc
66
     *
67
     * @return string
68
     */
69
    public function getName()
70
    {
71
        return $this->name;
72
    }
73
74
    /**
75
     * @inheritdoc
76
     *
77
     * @return array
78
     */
79
    public function getParameters()
80
    {
81
        return $this->parameters;
82
    }
83
}
84