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

InfluxDbEventListener::onInfluxDbEventDispatched()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 20
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 4.128
Metric Value
dl 0
loc 20
ccs 8
cts 10
cp 0.8
rs 9.2
cc 4
eloc 10
nc 4
nop 1
crap 4.128
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