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

EndpointFactory::create()   B

Complexity

Conditions 3
Paths 3

Size

Total Lines 27
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 18
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 27
ccs 18
cts 18
cp 1
rs 8.8571
c 0
b 0
f 0
cc 3
eloc 18
nc 3
nop 2
crap 3
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
}