PoolFactory::extractHostAndPort()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 7
ccs 5
cts 5
cp 1
rs 9.4285
cc 2
eloc 4
nc 2
nop 1
crap 2
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