Issues (137)

src/Drivers/Pdo/Connection.php (3 issues)

1
<?php
2
3
namespace Foolz\SphinxQL\Drivers\Pdo;
4
5
use Foolz\SphinxQL\Drivers\ConnectionBase;
6
use Foolz\SphinxQL\Drivers\MultiResultSet;
7
use Foolz\SphinxQL\Drivers\ResultSet;
8
use Foolz\SphinxQL\Exception\ConnectionException;
9
use Foolz\SphinxQL\Exception\DatabaseException;
10
use Foolz\SphinxQL\Exception\SphinxQLException;
11
use PDO;
12
use PDOException;
13
14
class Connection extends ConnectionBase
15
{
16
    /**
17
     * @inheritdoc
18
     */
19
    public function query($query)
20
    {
21
        $this->ensureConnection();
22
23
        $statement = $this->connection->prepare($query);
0 ignored issues
show
The method prepare() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

23
        /** @scrutinizer ignore-call */ 
24
        $statement = $this->connection->prepare($query);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
24
25
        try {
26
            $statement->execute();
27
        } catch (PDOException $exception) {
28
            throw new DatabaseException('[' . $exception->getCode() . '] ' . $exception->getMessage() . ' [' . $query . ']',
29
                (int)$exception->getCode(), $exception);
30
        }
31
32
        return new ResultSet(new ResultSetAdapter($statement));
0 ignored issues
show
It seems like $statement can also be of type mysqli_stmt; however, parameter $statement of Foolz\SphinxQL\Drivers\P...tAdapter::__construct() does only seem to accept PDOStatement, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

32
        return new ResultSet(new ResultSetAdapter(/** @scrutinizer ignore-type */ $statement));
Loading history...
33
    }
34
35
    /**
36
     * @inheritdoc
37
     */
38
    public function connect()
39
    {
40
        $params = $this->getParams();
41
42
        $dsn = 'mysql:';
43
        if (isset($params['host']) && $params['host'] != '') {
44
            $dsn .= 'host=' . $params['host'] . ';';
45
        }
46
        if (isset($params['port'])) {
47
            $dsn .= 'port=' . $params['port'] . ';';
48
        }
49
        if (isset($params['charset'])) {
50
            $dsn .= 'charset=' . $params['charset'] . ';';
51
        }
52
53
        if (isset($params['socket']) && $params['socket'] != '') {
54
            $dsn .= 'unix_socket=' . $params['socket'] . ';';
55
        }
56
57
        try {
58
            $con = new PDO($dsn);
59
        } catch (PDOException $exception) {
60
            throw new ConnectionException($exception->getMessage(), $exception->getCode(), $exception);
61
        }
62
63
        $this->connection = $con;
64
        $this->connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
65
66
        return true;
67
    }
68
69
    /**
70
     * @return bool
71
     * @throws ConnectionException
72
     */
73
    public function ping()
74
    {
75
        $this->ensureConnection();
76
77
        return $this->connection !== null;
78
    }
79
80
    /**
81
     * @inheritdoc
82
     */
83
    public function multiQuery(array $queue)
84
    {
85
        $this->ensureConnection();
86
87
        if (count($queue) === 0) {
88
            throw new SphinxQLException('The Queue is empty.');
89
        }
90
91
        try {
92
            $statement = $this->connection->query(implode(';', $queue));
93
        } catch (PDOException $exception) {
94
            throw new DatabaseException($exception->getMessage() .' [ '.implode(';', $queue).']', $exception->getCode(), $exception);
95
        }
96
97
        return new MultiResultSet(new MultiResultSetAdapter($statement));
98
    }
99
100
    /**
101
     * @inheritdoc
102
     */
103
    public function escape($value)
104
    {
105
        $this->ensureConnection();
106
107
        return $this->connection->quote($value);
0 ignored issues
show
The method quote() does not exist on mysqli. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

107
        return $this->connection->/** @scrutinizer ignore-call */ quote($value);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
108
    }
109
}
110