Completed
Push — master ( 2910fa...e89be3 )
by Jonas
03:40
created

EntityManagerFactory   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 6

Test Coverage

Coverage 0%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 14 2
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of SteamScore.
7
 *
8
 * (c) SteamScore <[email protected]>
9
 *
10
 * This Source Code Form is subject to the terms of the Mozilla Public
11
 * License, v. 2.0. If a copy of the MPL was not distributed with this
12
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
13
 */
14
15
namespace SteamScore\Api\Domain\Factories;
16
17
use Doctrine\DBAL\Types\Type;
18
use Doctrine\ORM\EntityManager;
19
use Doctrine\ORM\EntityManagerInterface;
20
use Doctrine\ORM\Mapping\Driver\SimplifiedXmlDriver;
21
use Doctrine\ORM\Tools\Setup;
22
use Interop\Container\ContainerInterface;
23
use Ramsey\Uuid\Doctrine\UuidBinaryType;
24
25
final class EntityManagerFactory
26
{
27
    /**
28
     * Creates an instanced implementation of `Doctrine\ORM\EntityManagerInterface`.
29
     *
30
     * @param ContainerInterface $container
31
     *
32
     * @return EntityManagerInterface
33
     */
34
    public function __invoke(ContainerInterface $container) : EntityManagerInterface
35
    {
36
        if (Type::hasType('uuid_binary') === false) {
37
            Type::addType('uuid_binary', UuidBinaryType::class);
38
        }
39
40
        $appConfig = $container->get('config');
41
        $ormConfig = Setup::createConfiguration($appConfig['debug'], $appConfig['orm']['proxies']);
42
        $driver = new SimplifiedXmlDriver($appConfig['orm']['mapping']);
43
44
        $ormConfig->setMetadataDriverImpl($driver);
45
46
        return EntityManager::create($appConfig['orm']['connection'], $ormConfig);
47
    }
48
}
49