Completed
Push — master ( ad4614...2265e9 )
by Konstantin
06:23
created

Connection.php (3 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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
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
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...
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 2
        }
105
106 3
        return $this->escaper;
107
    }
108
109
    public function checkConnection()
110
    {
111
        $this->conn->checkConnection();
112
    }
113
114
    /**
115
     * @return QueryBuilder
116
     */
117
    public function createQueryBuilder()
118
    {
119
        return new QueryBuilder($this);
120
    }
121
122 3
    protected function prepareQuery($query, $params)
123
    {
124 3
        return Util::prepareQuery($query, $params, $this->getEscaper());
125
    }
126
}
127