Passed
Branch master (feff43)
by Pedro
04:38 queued 22s
created

TransportFactory::create()   B

Complexity

Conditions 5
Paths 8

Size

Total Lines 17
Code Lines 11

Duplication

Lines 7
Ratio 41.18 %

Code Coverage

Tests 12
CRAP Score 5

Importance

Changes 0
Metric Value
dl 7
loc 17
ccs 12
cts 12
cp 1
rs 8.8571
c 0
b 0
f 0
cc 5
eloc 11
nc 8
nop 2
crap 5
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
 
16
    /**
17
     * {@inheritDoc}
18
     */
19 10
    protected function create(ServiceLocatorInterface $serviceLocator, $config)
20
    {
21 10
        $retries = isset($config['retries']) ? $config['retries'] : 2;
22 10
        $sniffOnStart = isset($config['sniff_on_start']) ? $config['sniff_on_start'] : false;
23 10
        $connectionPool = $serviceLocator->get($config['connection_pool']);
24
        
25 10 View Code Duplication
        if (!$connectionPool instanceof AbstractConnectionPool) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
26 1
            throw new ServiceNotCreatedException(sprintf(
27 1
                "The connection pool must be an instance of %s, %s given",
28 1
                AbstractConnectionPool::class,
29 1
                is_object($connectionPool) ? get_class($connectionPool) : gettype($connectionPool)
30 1
            ));
31
        }
32 9
        $loggers = $serviceLocator->get($config['loggers']);
33
        
34 9
        return new Transport($retries, $sniffOnStart, $connectionPool, $loggers['logger']);
35
    }
36
37
    /**
38
     * {@inheritDoc}
39
     */
40 10
    public function getServiceType()
41
    {
42 10
        return 'transport';
43
    }
44
}
45