Completed
Push — master ( d8dd7c...fad061 )
by Rasmus
03:55 queued 01:13
created

DatabaseContainer   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 60
Duplicated Lines 53.33 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 80%

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 1
dl 32
loc 60
c 0
b 0
f 0
ccs 16
cts 20
cp 0.8
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getType() 16 16 3
A getSchema() 16 16 3
A hasType() 0 4 1
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\model;
4
5
use mindplay\sql\model\schema\Schema;
6
use mindplay\sql\model\schema\Type;
7
use mindplay\unbox\Container;
8
use UnexpectedValueException;
9
10
/**
11
 * This class implements a dedicated dependency injection container for the database domain.
12
 */
13
class DatabaseContainer extends Container implements TypeProvider, TableFactory
14
{
15
    /**
16
     * @inheritdoc
17
     */
18 1 View Code Duplication
    public function getType($type_name)
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...
19
    {
20 1
        if (! $this->has($type_name)) {
21 1
            $this->inject($type_name, $this->create($type_name)); // auto-wiring
22
        }
23
24 1
        $type = $this->get($type_name);
25
26 1
        if (! $type instanceof Type) {
27
            $class_name = get_class($type);
28
29
            throw new UnexpectedValueException("{$class_name} does not implement the Type interface");
30
        }
31
        
32 1
        return $type;
33
    }
34
35
    /**
36
     * @param string Schema class-name
37
     *
38
     * @return Schema
39
     */
40 1 View Code Duplication
    public function getSchema($schema_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...
41
    {
42 1
        if (! $this->has($schema_type)) {
43 1
            $this->inject($schema_type, $this->create($schema_type)); // auto-wiring
44
        }
45
46 1
        $schema_type = $this->get($schema_type);
47
48 1
        if (! $schema_type instanceof Schema) {
49
            $class_name = get_class($schema_type);
50
51
            throw new UnexpectedValueException("{$class_name} does not extend the Schema class");
52
        }
53
54 1
        return $schema_type;
55
    }
56
57
    /**
58
     * @inheritdoc
59
     */
60 1
    public function hasType($type_name)
61
    {
62 1
        return $this->has($type_name);
63
    }
64
    
65
    /**
66
     * @inheritdoc
67
     */
68 1
    public function createTable($class_name, $table_name, $alias)
69
    {
70 1
        return $this->create($class_name, ['name' => $table_name, 'alias' => $alias]);
71
    }
72
}
73