Completed
Push — master ( 9ab4b9...065cdd )
by Alejandro
09:44
created

EntityManagerFactory   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 100%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
B __invoke() 0 17 8
1
<?php
2
namespace Shlinkio\Shlink\Common\Factory;
3
4
use Doctrine\Common\Cache\ArrayCache;
5
use Doctrine\Common\Cache\Cache;
6
use Doctrine\ORM\EntityManager;
7
use Doctrine\ORM\Tools\Setup;
8
use Interop\Container\ContainerInterface;
9
use Interop\Container\Exception\ContainerException;
10
use Zend\ServiceManager\Exception\ServiceNotCreatedException;
11
use Zend\ServiceManager\Exception\ServiceNotFoundException;
12
use Zend\ServiceManager\Factory\FactoryInterface;
13
14
class EntityManagerFactory implements FactoryInterface
15
{
16
    /**
17
     * Create an object
18
     *
19
     * @param  ContainerInterface $container
20
     * @param  string $requestedName
21
     * @param  null|array $options
22
     * @return object
23
     * @throws ServiceNotFoundException if unable to resolve the service.
24
     * @throws ServiceNotCreatedException if an exception is raised when
25
     *     creating a service.
26
     * @throws ContainerException if any other error occurs
27
     */
28 1
    public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
29
    {
30 1
        $globalConfig = $container->get('config');
31 1
        $isDevMode = isset($globalConfig['debug']) ? ((bool) $globalConfig['debug']) : false;
32 1
        $cache = $container->has(Cache::class) ? $container->get(Cache::class) : new ArrayCache();
33 1
        $emConfig = isset($globalConfig['entity_manager']) ? $globalConfig['entity_manager'] : [];
34 1
        $connecitonConfig = isset($emConfig['connection']) ? $emConfig['connection'] : [];
35 1
        $ormConfig = isset($emConfig['orm']) ? $emConfig['orm'] : [];
36
37 1
        return EntityManager::create($connecitonConfig, Setup::createAnnotationMetadataConfiguration(
38 1
            isset($ormConfig['entities_paths']) ? $ormConfig['entities_paths'] : [],
39 1
            $isDevMode,
40 1
            isset($ormConfig['proxies_dir']) ? $ormConfig['proxies_dir'] : null,
41 1
            $cache,
42
            false
43 1
        ));
44
    }
45
}
46