1 | <?php |
||||
2 | /* |
||||
3 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
4 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
5 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||||
6 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||||
7 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
8 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||||
9 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||||
10 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||||
11 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
12 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
13 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
14 | * |
||||
15 | * This software consists of voluntary contributions made by many individuals |
||||
16 | * and is licensed under the MIT license. For more information, see |
||||
17 | * <http://www.doctrine-project.org>. |
||||
18 | */ |
||||
19 | |||||
20 | namespace Doctrine\DBAL\Driver; |
||||
21 | |||||
22 | use PDO; |
||||
23 | |||||
24 | /** |
||||
25 | * PDO implementation of the Connection interface. |
||||
26 | * Used by all PDO-based drivers. |
||||
27 | * |
||||
28 | * @since 2.0 |
||||
29 | */ |
||||
30 | class PDOConnection extends PDO implements Connection, ServerInfoAwareConnection |
||||
31 | { |
||||
32 | /** |
||||
33 | * @param string $dsn |
||||
34 | * @param string|null $user |
||||
35 | * @param string|null $password |
||||
36 | * @param array|null $options |
||||
37 | * |
||||
38 | * @throws PDOException in case of an error. |
||||
39 | */ |
||||
40 | 47 | public function __construct($dsn, $user = null, $password = null, array $options = null) |
|||
41 | { |
||||
42 | try { |
||||
43 | 47 | parent::__construct($dsn, $user, $password, $options); |
|||
44 | 46 | $this->setAttribute(PDO::ATTR_STATEMENT_CLASS, ['Doctrine\DBAL\Driver\PDOStatement', []]); |
|||
45 | 46 | $this->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); |
|||
46 | 2 | } catch (\PDOException $exception) { |
|||
47 | 2 | throw new PDOException($exception); |
|||
48 | } |
||||
49 | 46 | } |
|||
50 | |||||
51 | /** |
||||
52 | * {@inheritdoc} |
||||
53 | */ |
||||
54 | 146 | public function exec($statement) |
|||
55 | { |
||||
56 | try { |
||||
57 | 146 | return parent::exec($statement); |
|||
58 | 53 | } catch (\PDOException $exception) { |
|||
59 | 53 | throw new PDOException($exception); |
|||
60 | } |
||||
61 | } |
||||
62 | |||||
63 | /** |
||||
64 | * {@inheritdoc} |
||||
65 | */ |
||||
66 | public function getServerVersion() |
||||
67 | { |
||||
68 | return PDO::getAttribute(PDO::ATTR_SERVER_VERSION); |
||||
0 ignored issues
–
show
Bug
Best Practice
introduced
by
![]() |
|||||
69 | } |
||||
70 | |||||
71 | /** |
||||
72 | * {@inheritdoc} |
||||
73 | */ |
||||
74 | 130 | public function prepare($prepareString, $driverOptions = []) |
|||
75 | { |
||||
76 | try { |
||||
77 | 130 | return parent::prepare($prepareString, $driverOptions); |
|||
0 ignored issues
–
show
The expression
return parent::prepare($...String, $driverOptions) returns the type PDOStatement which is incompatible with the return type mandated by Doctrine\DBAL\Driver\Connection::prepare() of Doctrine\DBAL\Driver\Statement .
In the issue above, the returned value is violating the contract defined by the mentioned interface. Let's take a look at an example: interface HasName {
/** @return string */
public function getName();
}
class Name {
public $name;
}
class User implements HasName {
/** @return string|Name */
public function getName() {
return new Name('foo'); // This is a violation of the ``HasName`` interface
// which only allows a string value to be returned.
}
}
![]() |
|||||
78 | 3 | } catch (\PDOException $exception) { |
|||
79 | 3 | throw new PDOException($exception); |
|||
80 | } |
||||
81 | } |
||||
82 | |||||
83 | /** |
||||
84 | * {@inheritdoc} |
||||
85 | */ |
||||
86 | 165 | public function query() |
|||
87 | { |
||||
88 | 165 | $args = func_get_args(); |
|||
89 | 165 | $argsCount = count($args); |
|||
90 | |||||
91 | try { |
||||
92 | 165 | View Code Duplication | if ($argsCount == 4) { |
||
0 ignored issues
–
show
This code seems to be duplicated across 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. ![]() |
|||||
93 | return parent::query($args[0], $args[1], $args[2], $args[3]); |
||||
0 ignored issues
–
show
The call to
PDO::query() has too many arguments starting with $args[1] .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue. If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above. ![]() The expression
return parent::query($ar...1], $args[2], $args[3]) returns the type PDOStatement which is incompatible with the return type mandated by Doctrine\DBAL\Driver\Connection::query() of Doctrine\DBAL\Driver\Statement .
In the issue above, the returned value is violating the contract defined by the mentioned interface. Let's take a look at an example: interface HasName {
/** @return string */
public function getName();
}
class Name {
public $name;
}
class User implements HasName {
/** @return string|Name */
public function getName() {
return new Name('foo'); // This is a violation of the ``HasName`` interface
// which only allows a string value to be returned.
}
}
![]() |
|||||
94 | } |
||||
95 | |||||
96 | 165 | View Code Duplication | if ($argsCount == 3) { |
||
0 ignored issues
–
show
This code seems to be duplicated across 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. ![]() |
|||||
97 | return parent::query($args[0], $args[1], $args[2]); |
||||
0 ignored issues
–
show
The expression
return parent::query($args[0], $args[1], $args[2]) returns the type PDOStatement which is incompatible with the return type mandated by Doctrine\DBAL\Driver\Connection::query() of Doctrine\DBAL\Driver\Statement .
In the issue above, the returned value is violating the contract defined by the mentioned interface. Let's take a look at an example: interface HasName {
/** @return string */
public function getName();
}
class Name {
public $name;
}
class User implements HasName {
/** @return string|Name */
public function getName() {
return new Name('foo'); // This is a violation of the ``HasName`` interface
// which only allows a string value to be returned.
}
}
![]() |
|||||
98 | } |
||||
99 | |||||
100 | 165 | if ($argsCount == 2) { |
|||
101 | return parent::query($args[0], $args[1]); |
||||
0 ignored issues
–
show
The expression
return parent::query($args[0], $args[1]) returns the type PDOStatement which is incompatible with the return type mandated by Doctrine\DBAL\Driver\Connection::query() of Doctrine\DBAL\Driver\Statement .
In the issue above, the returned value is violating the contract defined by the mentioned interface. Let's take a look at an example: interface HasName {
/** @return string */
public function getName();
}
class Name {
public $name;
}
class User implements HasName {
/** @return string|Name */
public function getName() {
return new Name('foo'); // This is a violation of the ``HasName`` interface
// which only allows a string value to be returned.
}
}
![]() |
|||||
102 | } |
||||
103 | |||||
104 | 165 | return parent::query($args[0]); |
|||
0 ignored issues
–
show
The expression
return parent::query($args[0]) returns the type PDOStatement which is incompatible with the return type mandated by Doctrine\DBAL\Driver\Connection::query() of Doctrine\DBAL\Driver\Statement .
In the issue above, the returned value is violating the contract defined by the mentioned interface. Let's take a look at an example: interface HasName {
/** @return string */
public function getName();
}
class Name {
public $name;
}
class User implements HasName {
/** @return string|Name */
public function getName() {
return new Name('foo'); // This is a violation of the ``HasName`` interface
// which only allows a string value to be returned.
}
}
![]() |
|||||
105 | 6 | } catch (\PDOException $exception) { |
|||
106 | 6 | throw new PDOException($exception); |
|||
107 | } |
||||
108 | } |
||||
109 | |||||
110 | /** |
||||
111 | * {@inheritdoc} |
||||
112 | */ |
||||
113 | 4 | public function quote($input, $type = \PDO::PARAM_STR) |
|||
114 | { |
||||
115 | 4 | return parent::quote($input, $type); |
|||
116 | } |
||||
117 | |||||
118 | /** |
||||
119 | * {@inheritdoc} |
||||
120 | */ |
||||
121 | 2 | public function lastInsertId($name = null) |
|||
122 | { |
||||
123 | 2 | return parent::lastInsertId($name); |
|||
124 | } |
||||
125 | |||||
126 | /** |
||||
127 | * {@inheritdoc} |
||||
128 | */ |
||||
129 | 1 | public function requiresQueryForServerVersion() |
|||
130 | { |
||||
131 | 1 | return false; |
|||
132 | } |
||||
133 | } |
||||
134 |