EntityManagerFactory::getOptionsClass()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace DoctrineORMModule\Service;
6
7
use Doctrine\ORM\EntityManager;
8
use DoctrineModule\Service\AbstractFactory;
9
use DoctrineORMModule\Options\EntityManager as DoctrineORMModuleEntityManager;
10
use Interop\Container\ContainerInterface;
11
12
class EntityManagerFactory extends AbstractFactory
13
{
14
    /**
15
     * {@inheritDoc}
16
     *
17
     * @return EntityManager
18
     */
19 72
    public function __invoke(ContainerInterface $container, $requestedName, ?array $options = null)
20
    {
21 72
        $options    = $this->getOptions($container, 'entitymanager');
22 72
        $connection = $container->get($options->getConnection());
23 72
        $config     = $container->get($options->getConfiguration());
24
25
        // initializing the resolver
26
        // @todo should actually attach it to a fetched event manager here, and not
27
        //       rely on its factory code
28 72
        $container->get($options->getEntityResolver());
29
30 72
        return EntityManager::create($connection, $config);
31
    }
32
33
    /**
34
     * {@inheritDoc}
35
     *
36
     * @return EntityManager
37
     */
38 72
    public function createService(ContainerInterface $container)
39
    {
40 72
        return $this($container, EntityManager::class);
41
    }
42
43 72
    public function getOptionsClass() : string
44
    {
45 72
        return DoctrineORMModuleEntityManager::class;
46
    }
47
}
48