Completed
Push — master ( c2bacd...81a0c2 )
by Park Jong-Hun
08:02
created

DatabaseManager   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 1
cbo 2
dl 0
loc 40
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A getInstance() 0 10 2
A setConfig() 0 4 1
A getEntityManager() 0 8 1
1
<?php
2
3
namespace Core;
4
5
use Doctrine\ORM\Tools\Setup;
6
use Doctrine\ORM\EntityManager;
7
8
class DatabaseManager
9
{
10
11
    private $config = [];
12
13
    private function __construct()
14
    {
15
    }
16
17
    /**
18
     * @return self
19
     */
20
    public static function getInstance()
21
    {
22
        static $instance = null;
23
24
        if ($instance === null) {
25
            $instance = new self();
26
        }
27
28
        return $instance;
29
    }
30
31
    public function setConfig(array $config)
32
    {
33
        $this->config = $config;
34
    }
35
36
    /**
37
     * @return EntityManager
38
     */
39
    public function getEntityManager()
40
    {
41
        $config = Setup::createAnnotationMetadataConfiguration(
42
                    $this->config['entityPath'],
43
                    $this->config['devMode']
44
                    );
45
        return EntityManager::create($this->config['connections'][$this->config['defaultConnection']], $config);
46
    }
47
}
48