Completed
Push — master ( a53983...d98a20 )
by Daniel
02:46 queued 26s
created

EventTrap::getTrappedEvents()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
/**
3
 * @package event
4
 */
5
6
7
namespace Mleko\Event\Listener;
8
9
10
class EventTrap implements \Mleko\Event\Listener
11
{
12
13
    /** @var object[] */
14
    private $trappedEvents;
15
16
    /** @var boolean */
17
    private $oneTime;
18
19
    /**
20
     * EventTrap constructor.
21
     * @param bool $oneTime
22
     */
23 2
    public function __construct($oneTime = true)
24
    {
25 2
        $this->oneTime = $oneTime;
26 2
        $this->trappedEvents = [];
27 2
    }
28
29
30
    /**
31
     * @param object $event
32
     * @param \Mleko\Event\Meta $meta
33
     */
34 2
    public function handle($event, \Mleko\Event\Meta $meta)
35
    {
36 2
        if ($this->oneTime && $this->trappedEvents) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->trappedEvents of type object[] is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
37 1
            return;
38
        }
39 2
        $this->trappedEvents[] = $event;
40 2
    }
41
42
    /**
43
     * @return object[]
44
     */
45 2
    public function getTrappedEvents()
46
    {
47 2
        return $this->trappedEvents;
48
    }
49
50
    /**
51
     * @return null|object
52
     */
53 1
    public function getFirstEvent()
54
    {
55 1
        return isset($this->trappedEvents[0]) ? $this->trappedEvents[0] : null;
56
    }
57
58
}
59