Completed
Pull Request — master (#27)
by Frederic
05:43
created

SendMetricOnDaemonStopped   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 80%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 0
loc 34
ccs 8
cts 10
cp 0.8
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A handle() 0 8 2
A isListener() 0 4 1
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