Completed
Push — master ( e2b0ed...de1bfb )
by Alessandro
02:16 queued 14s
created

InfluxDbClientFactory::buildUdpClient()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 7
ccs 0
cts 6
cp 0
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
crap 2
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 13 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\Services\Clients;
4
5
use InfluxDB\Client;
6
use InfluxDB\Database;
7
use InfluxDB\Driver\UDP;
8
9
/**
10
 * Class InfluxDbClientFactory
11
 * @package Algatux\InfluxDbBundle\Services\Clients
12
 */
13
class InfluxDbClientFactory
14
{
15
16
    /** @var string  */
17
    private $host;
18
19
    /** @var string  */
20
    private $udpPort;
21
22
    /** @var string  */
23
    private $httpPort;
24
25
    /** @var string  */
26
    private $database;
27
28
    /**
29
     * InfluxDbClientFactory constructor.
30
     * @param string $host
31
     * @param string $database
32
     * @param string $udpPort
33
     * @param string $httpPort
34
     */
35
    public function __construct($host, $database, $udpPort, $httpPort)
36
    {
37
        $this->host = $host;
38
        $this->database = $database;
39
        $this->udpPort = $udpPort;
40
        $this->httpPort = $httpPort;
41
    }
42
43
    /**
44
     * @return Database
45
     */
46
    public function buildUdpClient(): Database
47
    {
48
        $client = new Client($this->host,$this->udpPort);
49
        $client->setDriver(new UDP($this->host, $this->udpPort));
50
51
        return $client->selectDB($this->database);
52
    }
53
54
    /**
55
     * @return Database
56
     */
57
    public function buildHttpClient(): Database
58
    {
59
        $client = new Client($this->host,$this->httpPort);
60
61
        return $client->selectDB($this->database);
62
    }
63
64
}
65