Passed
Push — master ( feff43...162861 )
by Pedro
41s
created

TransportFactory::create()   A

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 0
Metric Value
dl 0
loc 18
ccs 12
cts 12
cp 1
rs 9.2
c 0
b 0
f 0
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 Zend\ServiceManager\Exception\ServiceNotCreatedException;
8
use Zend\ServiceManager\ServiceLocatorInterface;
9
10
/**
11
 * @author Pedro Alves <[email protected]>
12
 */
13
class TransportFactory extends AbstractFactory
14
{
15
    use InvalidTypeExceptionTrait;
16
 
17
    /**
18
     * {@inheritDoc}
19
     */
20 10
    protected function create(ServiceLocatorInterface $serviceLocator, $config)
21
    {
22 10
        $retries = isset($config['retries']) ? $config['retries'] : 2;
23 10
        $sniffOnStart = isset($config['sniff_on_start']) ? $config['sniff_on_start'] : false;
24 10
        $connectionPool = $serviceLocator->get($config['connection_pool']);
25
        
26 10
        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 9
        $loggers = $serviceLocator->get($config['loggers']);
35
        
36 9
        return new Transport($retries, $sniffOnStart, $connectionPool, $loggers['logger']);
37
    }
38
39
    /**
40
     * {@inheritDoc}
41
     */
42 10
    public function getServiceType()
43
    {
44 10
        return 'transport';
45
    }
46
}
47