EntityMapCacheFactory::createService()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 21
Code Lines 10

Duplication

Lines 21
Ratio 100 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 21
loc 21
rs 9.3142
cc 2
eloc 10
nc 2
nop 1
1
<?php
2
/**
3
 * @link    https://github.com/nnx-framework/doctrine
4
 * @author  Malofeykin Andrey  <[email protected]>
5
 */
6
namespace Nnx\Doctrine\Utils;
7
8
use Doctrine\Common\Cache\VoidCache;
9
use Zend\ServiceManager\FactoryInterface;
10
use Zend\ServiceManager\ServiceLocatorInterface;
11
use Nnx\ModuleOptions\ModuleOptionsPluginManagerInterface;
12
use Nnx\Doctrine\Options\ModuleOptionsInterface;
13
use Doctrine\Common\Cache\Cache;
14
15
/**
16
 * Class EntityMapCacheFactory
17
 *
18
 * @package Nnx\Doctrine\Utils
19
 */
20 View Code Duplication
class EntityMapCacheFactory implements FactoryInterface
0 ignored issues
show
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...
21
{
22
    /**
23
     * @param ServiceLocatorInterface $serviceLocator
24
     *
25
     * @return EntityMapBuilder
26
     *
27
     * @throws \Zend\ServiceManager\Exception\ServiceNotFoundException
28
     */
29
    public function createService(ServiceLocatorInterface $serviceLocator)
30
    {
31
        /** @var EntityMapBuilderInterface $entityMapBuilder */
32
        $entityMapBuilder = $serviceLocator->get(EntityMapBuilderInterface::class);
33
34
        /** @var ModuleOptionsPluginManagerInterface $moduleOptionsManager */
35
        $moduleOptionsManager = $serviceLocator->get(ModuleOptionsPluginManagerInterface::class);
36
        /** @var ModuleOptionsInterface $moduleOptions */
37
        $moduleOptions = $moduleOptionsManager->get(ModuleOptionsInterface::class);
38
        $cacheServiceName = $moduleOptions->getEntityMapDoctrineCache();
39
40
        if (null === $cacheServiceName) {
41
            $cache = new VoidCache();
42
        } else {
43
            /** @var Cache $cache */
44
            $cache = $serviceLocator->get($cacheServiceName);
45
        }
46
47
48
        return new EntityMapCache($entityMapBuilder, $cache, $moduleOptions);
49
    }
50
}
51