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

DatabaseContainer   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 40
Duplicated Lines 40 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 86.67%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 5
c 2
b 0
f 0
lcom 1
cbo 1
dl 16
loc 40
ccs 13
cts 15
cp 0.8667
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A getType() 16 16 3
A createTable() 0 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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