Completed
Push — master ( 9bf5de...63a510 )
by Peter
22:57
created

MemoryUniqueEventQueue::pop()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
/**
3
 * GpsLab component.
4
 *
5
 * @author    Peter Gribanov <[email protected]>
6
 * @copyright Copyright (c) 2016, Peter Gribanov
7
 * @license   http://opensource.org/licenses/MIT
8
 */
9
10
namespace GpsLab\Domain\Event\Queue;
11
12
use GpsLab\Domain\Event\EventInterface;
13
14
class MemoryUniqueEventQueue implements EventQueueInterface
15
{
16
    /**
17
     * @var EventInterface[]
18
     */
19
    private $events = [];
20
21
    /**
22
     * Push event to queue.
23
     *
24
     * @param EventInterface $event
25
     *
26
     * @return bool
27
     */
28
    public function push(EventInterface $event)
29
    {
30
        if (in_array($event, $this->events)) {
31
            return false;
32
        }
33
34
        $this->events[] = $event;
35
36
        return true;
37
    }
38
39
    /**
40
     * Pop event from queue. Return NULL if queue is empty.
41
     *
42
     * @return EventInterface|null
43
     */
44
    public function pop()
45
    {
46
        return array_pop($this->events);
47
    }
48
}
49