Completed
Push — master ( b268cf...c6aad7 )
by Oliver
07:45
created

Event   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 95
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 3
dl 0
loc 95
ccs 0
cts 41
cp 0
rs 10
c 0
b 0
f 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getInvokeArgs() 0 4 1
A __invoke() 0 6 1
A getName() 0 4 1
A offsetExists() 0 4 1
A offsetGet() 0 4 1
A offsetSet() 0 4 1
A offsetUnset() 0 4 1
A getMetadata() 0 6 1
1
<?php
2
3
namespace Metabor\Event;
4
5
use Metabor\KeyValue\Nullable;
6
use Metabor\Observer\Subject;
7
use Metabor\Statemachine\Util\ArrayAccessToArrayConverter;
8
use MetaborStd\Event\EventInterface;
9
use MetaborStd\MetadataInterface;
10
11
/**
12
 * @author Oliver Tischlinger
13
 */
14
class Event extends Subject implements EventInterface, \ArrayAccess, MetadataInterface
15
{
16
    /**
17
     * @var string
18
     */
19
    private $name;
20
21
    /**
22
     * @var array
23
     */
24
    private $invokeArgs = array();
25
26
    /**
27
     * @var \ArrayAccess
28
     */
29
    private $metadata;
30
31
    /**
32
     * @param string $name
33
     */
34
    public function __construct($name)
35
    {
36
        parent::__construct();
37
        $this->name = $name;
38
        $this->metadata = new Nullable();
39
    }
40
41
    /**
42
     * @see MetaborStd\Event.EventInterface::getInvokeArgs()
43
     */
44
    public function getInvokeArgs()
45
    {
46
        return $this->invokeArgs;
47
    }
48
49
    /**
50
     * @see \MetaborStd\CallbackInterface::__invoke()
51
     */
52
    public function __invoke()
53
    {
54
        $this->invokeArgs = func_get_args();
55
        $this->notify();
56
        $this->invokeArgs = array();
57
    }
58
59
    /**
60
     * @see \MetaborStd\NamedInterface::getName()
61
     */
62
    public function getName()
63
    {
64
        return $this->name;
65
    }
66
67
    /**
68
     * @see \ArrayAccess::offsetExists()
69
     */
70
    public function offsetExists($offset)
71
    {
72
        return $this->metadata->offsetExists($offset);
73
    }
74
75
    /**
76
     * @see \ArrayAccess::offsetGet()
77
     */
78
    public function offsetGet($offset)
79
    {
80
        return $this->metadata->offsetGet($offset);
81
    }
82
83
    /**
84
     * @see \ArrayAccess::offsetSet()
85
     */
86
    public function offsetSet($offset, $value)
87
    {
88
        $this->metadata->offsetSet($offset, $value);
89
    }
90
91
    /**
92
     * @see \ArrayAccess::offsetUnset()
93
     */
94
    public function offsetUnset($offset)
95
    {
96
        $this->metadata->offsetUnset($offset);
97
    }
98
99
    /**
100
     * @see \MetaborStd\MetadataInterface::getMetadata()
101
     */
102
    public function getMetadata()
103
    {
104
        $converter = new ArrayAccessToArrayConverter($this->metadata);
105
106
        return $converter->toArray();
107
    }
108
}
109