EntityManagerBuilder   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 4
dl 0
loc 72
ccs 20
cts 20
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A addType() 0 20 4
A getType() 0 4 1
A buildEntityManager() 0 4 1
1
<?php
2
3
namespace Doctrine\Tools;
4
5
use Doctrine\DBAL\DBALException;
6
use Doctrine\DBAL\Types\Type;
7
use Doctrine\ORM\Configuration;
8
use Doctrine\ORM\EntityManager;
9
10
class EntityManagerBuilder
11
{
12
    /**
13
     * @var EntityManager
14
     */
15
    private $entityManager;
16
17
    /**
18
     * Constructor.
19
     *
20
     * @param mixed         $conn
21
     * @param Configuration $config
22
     */
23 9
    public function __construct(
24
        $conn,
25
        Configuration $config
26
    ) {
27 9
        $this->entityManager = EntityManager::create($conn, $config);
28 9
    }
29
30
    /**
31
     * Add a type.
32
     *
33
     * @param string     $name
34
     * @param string     $className
35
     * @param callable[] $calls     an array of - [ methodName, [ methodParams... ] ]
36
     */
37 6
    public function addType(
38
        $name,
39
        $className,
40
        array $calls = []
41
    ) {
42 6
        if (!Type::hasType($name)) {
43 3
            Type::addType($name, $className);
44 2
        } else {
45 3
            Type::overrideType($name, $className);
46
        }
47
48 6
        if (!empty($calls)) {
49 3
            $type = self::getType($name);
50 3
            foreach ($calls as $call) {
51 3
                call_user_func_array([$type, $call[0]], $call[1]);
52 2
            }
53 2
        }
54
55 6
        $this->entityManager->getConnection()->getDatabasePlatform()->registerDoctrineTypeMapping($name, $name);
56 6
    }
57
58
    /**
59
     * Get the twitter type.
60
     *
61
     * @param string $typeName
62
     *
63
     * @throws DBALException
64
     *
65
     * @return Type
66
     */
67 3
    private static function getType($typeName)
68
    {
69 3
        return Type::getType($typeName);
70
    }
71
72
    /**
73
     * Builds the entity manager.
74
     *
75
     * @return EntityManager
76
     */
77 9
    public function buildEntityManager()
78
    {
79 9
        return $this->entityManager;
80
    }
81
}
82