EntityRepositoryManagerFactory::__invoke()   B
last analyzed

Complexity

Conditions 6
Paths 8

Size

Total Lines 27
Code Lines 12

Duplication

Lines 27
Ratio 100 %

Code Coverage

Tests 7
CRAP Score 8.6047

Importance

Changes 0
Metric Value
dl 27
loc 27
ccs 7
cts 12
cp 0.5833
rs 8.439
c 0
b 0
f 0
cc 6
eloc 12
nc 8
nop 3
crap 8.6047
1
<?php
2
/**
3
 * Polder Knowledge / entityservice-module (https://polderknowledge.com)
4
 *
5
 * @link https://github.com/polderknowledge/entityservice-module for the canonical source repository
6
 * @copyright Copyright (c) 2016 Polder Knowledge (https://polderknowledge.com)
7
 * @license https://github.com/polderknowledge/entityservice-module/blob/master/LICENSE.md MIT
8
 */
9
10
namespace PolderKnowledge\EntityService\Repository\Service;
11
12
use Interop\Container\ContainerInterface;
13
use Zend\ServiceManager\Config;
14
use Zend\ServiceManager\FactoryInterface;
15
use Zend\ServiceManager\ServiceLocatorInterface;
16
17 View Code Duplication
class EntityRepositoryManagerFactory implements FactoryInterface
0 ignored issues
show
Deprecated Code introduced by
The interface Zend\ServiceManager\FactoryInterface has been deprecated with message: Use Zend\ServiceManager\Factory\FactoryInterface 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...
Duplication introduced by
This class seems to be duplicated in 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...
18
{
19 6
    public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
20
    {
21 6
        $options = $options ?: [];
22
23 6
        $pluginManager = new EntityRepositoryManager($container, $options);
24
25
        // If this is in a zend-mvc application, the ServiceListener will inject
26
        // merged configuration during bootstrap.
27 6
        if ($container->has('ServiceListener')) {
28 3
            return $pluginManager;
29
        }
30
31
        // If we do not have a config service, nothing more to do
32 3
        if (!$container->has('config')) {
33 3
            return $pluginManager;
34
        }
35
36
        $config = $container->get('config');
37
        // If we do not have log_filters configuration, nothing more to do
38
        if (!isset($config['entity_repository_manager']) || !is_array($config['entity_repository_manager'])) {
39
            return $pluginManager;
40
        }
41
        // Wire service configuration for log_filters
42
        (new Config($config['entity_repository_manager']))->configureServiceManager($pluginManager);
43
44
        return $pluginManager;
45
    }
46
47 3
    public function createService(ServiceLocatorInterface $serviceLocator)
48
    {
49
        // @codeCoverageIgnoreStart
50
        if (method_exists($serviceLocator, 'getServiceLocator')) {
51
            $serviceLocator = $serviceLocator->getServiceLocator();
52
        }
53
        // @codeCoverageIgnoreEnd
54
55 3
        return $this($serviceLocator, '');
56
    }
57
}
58