Completed
Push — master ( 20d81d...6bd930 )
by Rasmus
02:25
created

DatabaseContainer::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 9
ccs 5
cts 5
cp 1
rs 9.6666
cc 1
eloc 4
nc 1
nop 0
crap 1
1
<?php
2
3
namespace mindplay\sql\framework;
4
5
use mindplay\sql\model\Type;
6
use mindplay\unbox\Container;
7
use UnexpectedValueException;
8
9
/**
10
 * This class implements a dedicated dependency injection container for the database domain.
11
 */
12
class DatabaseContainer extends Container implements TypeProvider, TableFactory
13
{
14 1
    public function __construct()
15
    {
16 1
        parent::__construct();
17
        
18
        // self-register:
19
20 1
        $this->set(TypeProvider::class, $this);
21 1
        $this->set(TableFactory::class, $this);
22 1
    }
23
24
    /**
25
     * @inheritdoc
26
     */
27 1 View Code Duplication
    public function getType($type)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
28
    {
29 1
        if (! $this->has($type)) {
30 1
            $this->register($type); // auto-wiring (for Types with no special constructor dependencies)
31
        }
32
33 1
        $type = $this->get($type);
34
35 1
        if (! $type instanceof Type) {
36
            $class_name = get_class($type);
37
38
            throw new UnexpectedValueException("{$class_name} does not implement the Type interface");
39
        }
40
41 1
        return $type;
42
    }
43
44
    /**
45
     * @inheritdoc
46
     */
47 1
    public function createTable($class_name, $table_name, $alias)
48
    {
49 1
        return $this->create($class_name, ['name' => $table_name, 'alias' => $alias]);
50
    }
51
}
52