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

EndpointFactory   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 3
dl 0
loc 43
ccs 20
cts 20
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
B create() 0 27 3
A getServiceType() 0 4 1
1
<?php
2
3
namespace ElasticsearchModule\Service;
4
5
use Elasticsearch\Serializers\SerializerInterface;
6
use ElasticsearchModule\Container\EndpointsInterface;
7
use Zend\ServiceManager\Exception\ServiceNotCreatedException;
8
use Zend\ServiceManager\ServiceLocatorInterface;
9
10
/**
11
 * @author Pedro Alves <[email protected]>
12
 */
13
class EndpointFactory extends AbstractFactory
14
{
15
    use InvalidTypeExceptionTrait;
16
    
17
    /**
18
     * {@inheritDoc}
19
     */
20 6
    protected function create(ServiceLocatorInterface $serviceLocator, $config)
21
    {
22 6
        $serializer = $this->getServiceOrClassObject($serviceLocator, $config['serializer']);
23
        
24 6
        if (!$serializer instanceof SerializerInterface) {
25 1
            throw $this->getException(
26 1
                'serializer',
27 1
                SerializerInterface::class,
28 1
                ServiceNotCreatedException::class,
29
                $serializer
30 1
            );
31
        }
32 5
        $transport = $serviceLocator->get($config['transport']);
33 5
        $container = $config['container'];
34 5
        $container = new $container($transport, $serializer);
35
        
36 5
        if (!$container instanceof EndpointsInterface) {
37 1
            throw $this->getException(
38 1
                'container',
39 1
                EndpointsInterface::class,
40 1
                ServiceNotCreatedException::class,
41
                $container
42 1
            );
43
        }
44
        
45 4
        return $container;
46
    }
47
48
    /**
49
     * {@inheritDoc}
50
     */
51 6
    public function getServiceType()
52
    {
53 6
        return 'endpoint';
54
    }
55
}