Completed
Push — master ( d8a2fe...e3b3f5 )
by Konstantin
03:02
created

Connection   A

Complexity

Total Complexity 17

Size/Duplication

Total Lines 112
Duplicated Lines 26.79 %

Coupling/Cohesion

Components 1
Dependencies 7

Test Coverage

Coverage 37.5%

Importance

Changes 0
Metric Value
wmc 17
lcom 1
cbo 7
dl 30
loc 112
ccs 18
cts 48
cp 0.375
rs 10
c 0
b 0
f 0

10 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A setLogger() 0 4 1
A getLogger() 0 4 1
A executeUpdate() 0 14 3
A executeQuery() 15 15 3
A executeMultiQuery() 15 15 3
A quote() 0 4 1
A getEscaper() 0 8 2
A createQueryBuilder() 0 4 1
A prepareQuery() 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 Brouzie\Sphinxy;
4
5
use Brouzie\Sphinxy\Connection\ConnectionInterface;
6
use Brouzie\Sphinxy\Logging\LoggerInterface;
7
use Brouzie\Sphinxy\Query\MultiResultSet;
8
use Brouzie\Sphinxy\Query\ResultSet;
9
10
class Connection
11
{
12
    /**
13
     * @var ConnectionInterface
14
     */
15
    private $conn;
16
17
    /**
18
     * @var Escaper
19
     */
20
    private $escaper;
21
22
    /**
23
     * @var LoggerInterface|null
24
     */
25
    private $logger;
26
27
    public function __construct(ConnectionInterface $conn)
28
    {
29
        $this->conn = $conn;
30
    }
31
32
    /**
33
     * @param LoggerInterface|null $logger
34
     */
35
    public function setLogger(LoggerInterface $logger = null)
36
    {
37
        $this->logger = $logger;
38
    }
39
40
    /**
41
     * @return LoggerInterface|null
42
     */
43
    public function getLogger()
44
    {
45
        return $this->logger;
46
    }
47
48 3
    public function executeUpdate($query, array $params = array())
49
    {
50 3
        if (null !== $this->logger) {
51
            $this->logger->startQuery($query);
52
        }
53
54 3
        $result = $this->conn->exec($this->prepareQuery($query, $params));
55
56 3
        if (null !== $this->logger) {
57
            $this->logger->stopQuery();
58
        }
59
60 3
        return $result;
61
    }
62
63 View Code Duplication
    public function executeQuery($query, array $params = array())
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...
64
    {
65
        if (null !== $this->logger) {
66
            $this->logger->startQuery($query, $params);
67
        }
68
69
        $result = $this->conn->query($this->prepareQuery($query, $params));
70
71
        if (null !== $this->logger) {
72
            $this->logger->stopQuery();
73
        }
74
        $meta = $this->conn->query('SHOW META');
75
76
        return new ResultSet($result, $meta);
77
    }
78
79 3 View Code Duplication
    public function executeMultiQuery($query, array $params = array(), array $types = array(), array $resultSetNames = array())
0 ignored issues
show
Unused Code introduced by
The parameter $types is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
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...
80
    {
81 3
        if (null !== $this->logger) {
82
            $this->logger->startQuery($query, $params);
83
        }
84
85 3
        $results = $this->conn->multiQuery($this->prepareQuery($query, $params), $resultSetNames);
86
87 3
        if (null !== $this->logger) {
88
            $this->logger->stopQuery();
89
        }
90 3
        $meta = $this->conn->query('SHOW META');
91
92 3
        return new MultiResultSet($results, $meta);
93
    }
94
95
    public function quote($value)
96
    {
97
        return $this->conn->quote($value);
98
    }
99
100 3
    public function getEscaper()
101
    {
102 3
        if (null === $this->escaper) {
103 3
            $this->escaper = new Escaper($this->conn);
104 3
        }
105
106 3
        return $this->escaper;
107
    }
108
109
    /**
110
     * @return QueryBuilder
111
     */
112
    public function createQueryBuilder()
113
    {
114
        return new QueryBuilder($this);
115
    }
116
117 3
    protected function prepareQuery($query, $params)
118
    {
119 3
        return Util::prepareQuery($query, $params, $this->getEscaper());
120
    }
121
}
122