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

TransportFactory   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 4
dl 0
loc 34
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 18 4
A getServiceType() 0 4 1
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