ExecuteQueries   A
last analyzed

Complexity

Total Complexity 15

Size/Duplication

Total Lines 99
Duplicated Lines 18.18 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
dl 18
loc 99
rs 10
c 0
b 0
f 0
wmc 15
lcom 1
cbo 0

14 Methods

Rating   Name   Duplication   Size   Complexity  
A affectedRows() 0 6 1
A query() 0 12 2
A selectDb() 0 6 1
A createDb() 9 9 1
A listTables() 9 9 1
A insertId() 0 6 1
A listDbs() 0 4 1
A dbName() 0 4 1
A dbQuery() 0 7 1
A dropDb() 0 4 1
A listFields() 0 4 1
A listProcesses() 0 4 1
A tablename() 0 4 1
A unbufferedQuery() 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 Mattbit\MysqlCompat\BridgeComponents;
4
5
use Mattbit\MysqlCompat\Connection;
6
use Mattbit\MysqlCompat\Exception\QueryException;
7
8
trait ExecuteQueries
9
{
10
    public function affectedRows(Connection $linkIdentifier = null)
11
    {
12
        $connection = $this->manager->getOpenConnectionOrFail($linkIdentifier);
13
14
        return $connection->getRowCount();
15
    }
16
17
    public function query($query, Connection $linkIdentifier = null)
18
    {
19
        $connection = $this->manager->getOpenConnectionOrFail($linkIdentifier);
20
21
        try {
22
            $result = $connection->query($query);
23
        } catch (QueryException $e) {
24
            return false;
25
        }
26
27
        return $result;
28
    }
29
30
    public function selectDb($databaseName, Connection $linkIdentifier = null)
31
    {
32
        $connection = $this->manager->getOpenConnectionOrFail($linkIdentifier);
33
34
        return (bool) $connection->useDatabase($databaseName);
35
    }
36
37 View Code Duplication
    public function createDb($databaseName, Connection $linkIdentifier = null)
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...
38
    {
39
        $connection = $this->manager->getOpenConnectionOrFail($linkIdentifier);
40
41
        return $connection->parametrizedQuery(
42
            'CREATE DATABASE :databaseName',
43
            [':databaseName' => $databaseName]
44
        );
45
    }
46
47 View Code Duplication
    public function listTables($database, Connection $linkIdentifier = null)
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...
48
    {
49
        $connection = $this->manager->getOpenConnectionOrFail($linkIdentifier);
50
51
        return $connection->parametrizedQuery(
52
            'SHOW TABLES FROM :database',
53
            [':database' => $database]
54
        );
55
    }
56
57
    public function insertId(Connection $linkIdentifier = null)
58
    {
59
        $connection = $this->manager->getOpenConnectionOrFail($linkIdentifier);
60
61
        return (int) $connection->getLastInsertId();
62
    }
63
64
    public function listDbs()
65
    {
66
        // @todo
67
    }
68
69
    public function dbName()
70
    {
71
        // @todo
72
    }
73
74
    public function dbQuery($database, $query, Connection $linkIdentifier = null)
75
    {
76
        $connection = $this->manager->getOpenConnectionOrFail($linkIdentifier);
77
        $connection->useDatabase($database);
78
79
        return $connection->query($query);
80
    }
81
82
    public function dropDb()
83
    {
84
        // @todo
85
    }
86
87
    public function listFields()
88
    {
89
        // @todo
90
    }
91
92
    public function listProcesses()
93
    {
94
        // @todo
95
    }
96
97
    public function tablename()
98
    {
99
        // @todo
100
    }
101
102
    public function unbufferedQuery()
103
    {
104
        // @todo
105
    }
106
}
107