Total Complexity | 8 |
Total Lines | 52 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 0 |
1 | <?php |
||
19 | class EventCollection extends BaseObject implements EventCollectionInterface |
||
20 | { |
||
21 | /** |
||
22 | * @var EventInterface[] array of events (key => event). |
||
23 | */ |
||
24 | private $_events = []; |
||
25 | /** |
||
26 | * @var string event class name. |
||
27 | */ |
||
28 | public $eventClass = 'izumi\longpoll\Event'; |
||
29 | |||
30 | /** |
||
31 | * @inheritdoc |
||
32 | */ |
||
33 | 22 | public function addEvent($event) |
|
34 | { |
||
35 | 22 | if (!$event instanceof EventInterface) { |
|
36 | 15 | if (!is_array($event)) { |
|
37 | $event = [ |
||
38 | 13 | 'class' => $this->eventClass, |
|
39 | 13 | 'key' => $event, |
|
40 | ]; |
||
41 | } |
||
42 | 15 | $event = Yii::createObject($event); |
|
43 | 15 | if (!$event instanceof EventInterface) { |
|
44 | 1 | throw new InvalidConfigException('The event should be an instance of "\izumi\longpoll\EventInterface".'); |
|
45 | } |
||
46 | } |
||
47 | 21 | $this->_events[$event->getKey()] = $event; |
|
48 | |||
49 | 21 | return $event; |
|
50 | } |
||
51 | |||
52 | /** |
||
53 | * @inheritdoc |
||
54 | */ |
||
55 | 22 | public function getEvents() |
|
58 | } |
||
59 | |||
60 | /** |
||
61 | * @inheritdoc |
||
62 | */ |
||
63 | 23 | public function setEvents($events) |
|
71 | } |
||
72 | 22 | } |
|
74 |