Completed
Pull Request — master (#27)
by Frederic
04:50 queued 02:40
created

SendMetricOnDaemonStopped::handle()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 5
cts 5
cp 1
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 2
1
<?php
2
3
namespace Burrow\Event\Listener\Metric;
4
5
use Burrow\Event\DaemonStopped;
6
use Burrow\Event\Listener\ListenerException;
7
use Burrow\Metric\MetricService;
8
use League\Event\EventInterface;
9
use League\Event\ListenerInterface;
10
11
class SendMetricOnDaemonStopped implements ListenerInterface
12
{
13
    /** @var MetricService */
14
    private $metricService;
15
16
    /**
17
     * SendMetricOnDaemonStarted constructor.
18
     *
19
     * @param MetricService $metricService
20
     */
21 9
    public function __construct(MetricService $metricService)
22
    {
23 9
        $this->metricService = $metricService;
24 9
    }
25
26
    /**
27
     * @param EventInterface $event
28
     *
29
     * @throws ListenerException
30
     */
31 6
    public function handle(EventInterface $event)
32
    {
33 6
        if (!($event instanceof DaemonStopped)) {
34 3
            throw ListenerException::badEventGiven($event);
35
        }
36
37 3
        $this->metricService->increment('worker.stopped');
38 3
    }
39
40
    public function isListener($listener)
41
    {
42
        return $listener === $this;
43
    }
44
}
45