OneTimeListener::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
/**
3
 * @package narrator
4
 */
5
6
7
namespace Mleko\Narrator\Listener;
8
9
10
class OneTimeListener implements \Mleko\Narrator\Listener
11
{
12
    /** @var \Mleko\Narrator\Listener */
13
    private $wrappedListener;
14
15
    /** @var bool */
16
    private $fired = false;
17
18
    /**
19
     * OneTimeListener constructor.
20
     * @param \Mleko\Narrator\Listener $listener
21
     */
22 1
    public function __construct(\Mleko\Narrator\Listener $listener)
23
    {
24 1
        $this->wrappedListener = $listener;
25 1
    }
26
27 1
    public function handle($event, \Mleko\Narrator\Meta $meta)
28
    {
29 1
        if (!$this->fired) {
30 1
            $this->fired = true;
31 1
            $meta->getEventSource()->unsubscribe($meta->getMatchedName(), $this);
32 1
            $this->wrappedListener->handle($event, $meta);
33 1
        }
34 1
    }
35
36
}
37