Completed
Push — master ( bb7923...9f4ad0 )
by Alessandro
02:07
created

InfluxDbEventListener   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 85.71%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 1
cbo 2
dl 0
loc 42
ccs 12
cts 14
cp 0.8571
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A onInfluxDbEventDispatched() 0 20 4
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 12 and the first side effect is on line 2.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
declare(strict_types=1);
3
namespace Algatux\InfluxDbBundle\Events\Listeners;
4
use Algatux\InfluxDbBundle\Events\InfluxDbEvent;
5
use Algatux\InfluxDbBundle\Services\Clients\Contracts\ClientInterface;
6
use Algatux\InfluxDbBundle\Services\Clients\WriterClient;
7
8
/**
9
 * Class InfluxDbEventListener
10
 * @package Algatux\InfluxDbBundle\Events\Listeners
11
 */
12
class InfluxDbEventListener
13
{
14
15
    /** @var WriterClient  */
16
    private $httpWriter;
17
18
    /** @var WriterClient  */
19
    private $udpWriter;
20
21
    /**
22
     * InfluxDbEventListener constructor.
23
     * @param WriterClient $httpWriter
24
     * @param WriterClient $udpWriter
25
     */
26 2
    public function __construct(WriterClient $httpWriter, WriterClient $udpWriter)
27
    {
28 2
        $this->httpWriter = $httpWriter;
29 2
        $this->udpWriter = $udpWriter;
30 2
    }
31
32 2
    public function onInfluxDbEventDispatched(InfluxDbEvent $event): bool
33
    {
34
35 2
        if ($event->isPropagationStopped()) {
36
            return false;
37
        }
38
39 2
        if ($event->getWriteClient() === ClientInterface::UDP_CLIENT) {
40 1
            $this->udpWriter->write($event->getPoints(), ClientInterface::UDP_CLIENT);
41 1
            return true;
42
        }
43
44 1
        if ($event->getWriteClient() === ClientInterface::HTTP_CLIENT) {
45 1
            $this->httpWriter->write($event->getPoints(), ClientInterface::HTTP_CLIENT);
46 1
            return true;
47
        }
48
49
        return false;
50
51
    }
52
53
}
54