PoolFactory   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 100%

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 11 2
A extractHostAndPort() 0 7 2
A createServer() 0 4 1
1
<?php
2
3
4
namespace Beanie\Server;
5
6
7
use Beanie\Util\FactoryInterface;
8
use Beanie\Util\FactoryTrait;
9
10
class PoolFactory implements FactoryInterface
11
{
12
    use FactoryTrait;
13
14
    /**
15
     * @param array $serverList
16
     * @return Pool
17
     */
18 1
    public function create(array $serverList)
19
    {
20 1
        $servers = [];
21
22 1
        foreach ($serverList as $server) {
23 1
            list($host, $port) = $this->extractHostAndPort($server);
24 1
            $servers[] = $this->createServer($host, $port);
25 1
        }
26
27 1
        return new Pool($servers);
28
    }
29
30
    /**
31
     * @param string $server
32
     * @return array
33
     */
34 1
    protected function extractHostAndPort($server)
35
    {
36 1
        return (strpos($server, ':') !== false)
37 1
            ? explode(':', $server, 2)
38 1
            : [$server, Server::DEFAULT_PORT]
39 1
        ;
40
    }
41
42
    /**
43
     * @param string $host
44
     * @param int $port
45
     * @return Server
46
     */
47 1
    public function createServer($host, $port)
48
    {
49 1
        return new Server($host, $port);
50
    }
51
}
52