TransportFactory::create()   A
last analyzed

Complexity

Conditions 4
Paths 8

Size

Total Lines 18
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 18
ccs 12
cts 12
cp 1
rs 9.2
cc 4
eloc 12
nc 8
nop 2
crap 4
1
<?php
2
3
namespace ElasticsearchModule\Service;
4
5
use Elasticsearch\ConnectionPool\AbstractConnectionPool;
6
use Elasticsearch\Transport;
7
use Interop\Container\ContainerInterface;
8
use Zend\ServiceManager\Exception\ServiceNotCreatedException;
9
10
/**
11
 * @author Pedro Alves <[email protected]>
12
 */
13
class TransportFactory extends AbstractFactory
14
{
15
    use InvalidTypeExceptionTrait;
16
 
17
    /**
18
     * {@inheritDoc}
19
     */
20 11
    protected function create(ContainerInterface $container, $config)
21
    {
22 11
        $retries = isset($config['retries']) ? $config['retries'] : 2;
23 11
        $sniffOnStart = isset($config['sniff_on_start']) ? $config['sniff_on_start'] : false;
24 11
        $connectionPool = $container->get($config['connection_pool']);
25
        
26 11
        if (!$connectionPool instanceof AbstractConnectionPool) {
27 1
            throw $this->getException(
28 1
                'connection pool',
29 1
                AbstractConnectionPool::class,
30 1
                ServiceNotCreatedException::class,
31
                $connectionPool
32 1
            );
33
        }
34 10
        $loggers = $container->get($config['loggers']);
35
        
36 10
        return new Transport($retries, $sniffOnStart, $connectionPool, $loggers['logger']);
37
    }
38
39
    /**
40
     * {@inheritDoc}
41
     */
42 11
    public function getServiceType()
43
    {
44 11
        return 'transport';
45
    }
46
}
47