RepositoryAbstractFactory::createServiceWithName()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2

Importance

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