EntityManagerFactory::__invoke()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 14
ccs 8
cts 8
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 8
nc 2
nop 1
crap 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\Factory;
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 1
    public function __invoke(ContainerInterface $container): EntityManagerInterface
35
    {
36 1
        if (Type::hasType('uuid_binary') === false) {
37 1
            Type::addType('uuid_binary', UuidBinaryType::class);
38
        }
39
40 1
        $appConfig = $container->get('config');
41 1
        $ormConfig = Setup::createConfiguration($appConfig['debug'], $appConfig['orm']['proxies']);
42 1
        $driver = new SimplifiedXmlDriver($appConfig['orm']['mapping']);
43
44 1
        $ormConfig->setMetadataDriverImpl($driver);
45
46 1
        return EntityManager::create($appConfig['orm']['connection'], $ormConfig);
47
    }
48
}
49