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

EntityManagerFactory::__invoke()   B

Complexity

Conditions 8
Paths 32

Size

Total Lines 17
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 8

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 8
eloc 13
c 2
b 0
f 0
nc 32
nop 3
dl 0
loc 17
ccs 13
cts 13
cp 1
crap 8
rs 7.7777
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