Completed
Push — master ( 66da5b...1405d1 )
by Peter
03:10
created

MemoryUniqueEventQueue   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A push() 0 12 2
A pop() 0 4 1
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 1
    public function push(EventInterface $event)
29
    {
30 1
        $index = array_search($event, $this->events);
31
32 1
        if ($index !== false) {
33 1
            $this->events[$index] = $event; // override exists event
34 1
        } else {
35 1
            $this->events[] = $event;
36
        }
37
38 1
        return true;
39
    }
40
41
    /**
42
     * Pop event from queue. Return NULL if queue is empty.
43
     *
44
     * @return EventInterface|null
45
     */
46 1
    public function pop()
47
    {
48 1
        return array_shift($this->events);
49
    }
50
}
51