Completed
Push — master ( f707f5...a08928 )
by Rasmus
02:27
created

Database   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 51
Duplicated Lines 31.37 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 85.71%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 16
loc 51
wmc 5
lcom 0
cbo 1
ccs 12
cts 14
cp 0.8571
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
createDriver() 0 1 ?
A getSchema() 16 16 3
A sql() 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\query\SQLQuery;
6
use mindplay\sql\model\schema\Schema;
7
use UnexpectedValueException;
8
9
/**
10
 * This class implements the primary public API of the database model.
11
 */
12
abstract class Database
13
{
14
    /**
15
     * @var DatabaseContainer
16
     */
17
    protected $container;
18
    
19 1
    public function __construct()
20
    {
21 1
        $this->container = new DatabaseContainer();
22
23 1
        $this->container->set(Driver::class, $this->createDriver());
24 1
    }
25
    
26
    /**
27
     * @return Driver
28
     */
29
    abstract protected function createDriver();
30
31
    /**
32
     * @param string Schema class-name
33
     *
34
     * @return Schema
35
     */
36 1 View Code Duplication
    public function getSchema($schema)
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...
37
    {
38 1
        if (! $this->container->has($schema)) {
39 1
            $this->container->register($schema); // auto-wiring (for Schema with no special constructor dependencies)
40
        }
41
42 1
        $schema = $this->container->get($schema);
43
44 1
        if (! $schema instanceof Schema) {
45
            $class_name = get_class($schema);
46
47
            throw new UnexpectedValueException("{$class_name} does not extend the Schema class");
48
        }
49
50 1
        return $schema;
51
    }
52
    
53
    /**
54
     * @param string $sql
55
     * 
56
     * @return SQLQuery
57
     */
58 1
    public function sql($sql)
59
    {
60 1
        return $this->container->create(SQLQuery::class, ['sql' => $sql]);
61
    }
62
}
63