RepositoryAbstractFactory   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 8
lcom 0
cbo 2
dl 0
loc 48
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A canCreate() 0 4 1
A __invoke() 0 12 3
A canCreateServiceWithName() 0 10 2
A createServiceWithName() 0 10 2
1
<?php
2
/**
3
 * Polder Knowledge / entityservice (https://polderknowledge.com)
4
 *
5
 * @link https://github.com/polderknowledge/entityservice for the canonical source repository
6
 * @copyright Copyright (c) 2016 Polder Knowledge (https://polderknowledge.com)
7
 * @license https://github.com/polderknowledge/entityservice/blob/master/LICENSE.md MIT
8
 */
9
10
namespace PolderKnowledge\EntityService\Repository\Doctrine\Service;
11
12
use Interop\Container\ContainerInterface;
13
use PolderKnowledge\EntityService\Repository\Doctrine\ORMRepository;
14
use Zend\ServiceManager\AbstractFactoryInterface;
15
use Zend\ServiceManager\ServiceLocatorInterface;
16
17
/**
18
 * RepositoryAbstractFactory creates a default ORMRepository for an EntityService
19
 */
20
class RepositoryAbstractFactory implements AbstractFactoryInterface
0 ignored issues
show
Deprecated Code introduced by
The interface Zend\ServiceManager\AbstractFactoryInterface has been deprecated with message: Use Zend\ServiceManager\Factory\AbstractFactoryInterface instead.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
21
{
22
    /**
23
     * {@inheritdoc}
24
     */
25 3
    public function canCreate(ContainerInterface $container, $requestedName)
26
    {
27 3
        return true;
28
    }
29
30
    /**
31
     * {@inheritdoc}
32
     */
33 6
    public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
34
    {
35 6
        $doctrineServiceName = 'Doctrine\\ORM\\EntityManager';
36
37 6
        if ($options && array_key_exists('doctrine_entity_manager', $options)) {
38 3
            $doctrineServiceName = $options['doctrine_entity_manager'];
39 3
        }
40
41 6
        $entityManager = $container->get($doctrineServiceName);
42
43 6
        return new ORMRepository($entityManager, $requestedName);
44
    }
45
46 3
    public function canCreateServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName)
47
    {
48
        // @codeCoverageIgnoreStart
49
        if (method_exists($serviceLocator, 'getServiceLocator')) {
50
            $serviceLocator = $serviceLocator->getServiceLocator();
51
        }
52
        // @codeCoverageIgnoreEnd
53
54 3
        return $this->canCreate($serviceLocator, $requestedName);
55
    }
56
57 3
    public function createServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName)
58
    {
59
        // @codeCoverageIgnoreStart
60
        if (method_exists($serviceLocator, 'getServiceLocator')) {
61
            $serviceLocator = $serviceLocator->getServiceLocator();
62
        }
63
        // @codeCoverageIgnoreEnd
64
65 3
        return $this($serviceLocator, $requestedName);
66
    }
67
}
68