LocalUdpClientFactory   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
c 1
b 0
f 0
lcom 1
cbo 2
dl 0
loc 38
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
B __construct() 0 10 5
A getClient() 0 5 1
1
<?php
2
3
namespace Werkspot\Bundle\StatsdBundle\Service;
4
5
use Domnikl\Statsd\Connection\UdpSocket;
6
use Werkspot\Bundle\StatsdBundle\Client\StatsdClient;
7
use Werkspot\Bundle\StatsdBundle\Client\StatsdClientInterface;
8
9
class LocalUdpClientFactory implements StatsdClientFactoryInterface
10
{
11
    /**
12
     * @var string
13
     */
14
    private $applicationPrefix;
15
16
    /**
17
     * @var UdpSocket
18
     */
19
    private $connection;
20
21
    /**
22
     * @param string $applicationPrefix
23
     * @param array $connectionOptions
24
     */
25
    public function __construct($applicationPrefix = '', array $connectionOptions = [])
26
    {
27
        $host = isset($connectionOptions['host']) ? $connectionOptions['host'] : '127.0.0.1';
28
        $port = isset($connectionOptions['port']) ? $connectionOptions['port'] : '8125';
29
        $timeout = isset($connectionOptions['timeout']) ? $connectionOptions['timeout'] : null;
30
        $persistent = isset($connectionOptions['persistent']) ? $connectionOptions['persistent'] : false;
31
32
        $this->connection = new UdpSocket($host, $port, $timeout, $persistent);
33
        $this->applicationPrefix = $applicationPrefix;
34
    }
35
36
    /**
37
     * @param string $namespace
38
     *
39
     * @return StatsdClientInterface
40
     */
41
    public function getClient($namespace)
42
    {
43
        $namespace = $this->applicationPrefix . $namespace;
44
        return new StatsdClient($this->connection, $namespace);
45
    }
46
}
47