Conditions | 17 |
Paths | 1620 |
Total Lines | 92 |
Lines | 0 |
Ratio | 0 % |
Tests | 40 |
CRAP Score | 17.217 |
Changes | 0 |
Metric | Value |
---|---|
cc | 17 |
nc | 1620 |
nop | 5 |
dl | 0 |
loc | 92 |
ccs | 40 |
cts | 44 |
cp | 0.9091 |
crap | 17.217 |
rs | 1.0145 |
c | 0 |
b | 0 |
f | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
0 ignored issues
–
show
Coding Style
introduced
by
Loading history...
|
|||
2 | /** |
||
0 ignored issues
–
show
|
|||
3 | * php7-mysql-shim |
||
0 ignored issues
–
show
|
|||
4 | * |
||
5 | * @author Davey Shafik <[email protected]> |
||
0 ignored issues
–
show
|
|||
6 | * @copyright Copyright (c) 2017 Davey Shafik |
||
0 ignored issues
–
show
|
|||
7 | * @license MIT License |
||
0 ignored issues
–
show
|
|||
8 | * @link https://github.com/dshafik/php7-mysql-shim |
||
0 ignored issues
–
show
|
|||
9 | */ |
||
0 ignored issues
–
show
|
|||
10 | |||
11 | /** |
||
12 | * A drop-in replacement for ext/mysql in PHP 7+ using ext/mysqli instead |
||
13 | * |
||
14 | * This library is meant to be a _stop-gap_. It will be slower than using |
||
15 | * the native functions directly. |
||
16 | * |
||
17 | * You should switch to ext/pdo_mysql or ext/mysqli, and migrate to prepared |
||
18 | * queries (@see http://php.net/manual/en/pdo.prepared-statements.php) to |
||
19 | * ensure you are securely interacting with your database. |
||
20 | */ |
||
21 | namespace { |
||
22 | |||
23 | if (!extension_loaded('mysql')) { |
||
0 ignored issues
–
show
|
|||
24 | if (!extension_loaded('mysqli')) { |
||
0 ignored issues
–
show
|
|||
25 | trigger_error('php7-mysql-shim: ext/mysqli is required', E_USER_ERROR); |
||
0 ignored issues
–
show
|
|||
26 | } |
||
0 ignored issues
–
show
|
|||
27 | |||
28 | define('MYSQL_ASSOC', 1); |
||
0 ignored issues
–
show
|
|||
29 | define('MYSQL_NUM', 2); |
||
0 ignored issues
–
show
|
|||
30 | define('MYSQL_BOTH', 3); |
||
0 ignored issues
–
show
|
|||
31 | define('MYSQL_CLIENT_COMPRESS', 32); |
||
0 ignored issues
–
show
|
|||
32 | define('MYSQL_CLIENT_SSL', 2048); |
||
0 ignored issues
–
show
|
|||
33 | define('MYSQL_CLIENT_INTERACTIVE', 1024); |
||
0 ignored issues
–
show
|
|||
34 | define('MYSQL_CLIENT_IGNORE_SPACE', 256); |
||
0 ignored issues
–
show
|
|||
35 | |||
36 | function mysql_connect( |
||
0 ignored issues
–
show
The return type could not be reliably inferred; please add a
@return annotation.
Our type inference engine in quite powerful, but sometimes the code does not
provide enough clues to go by. In these cases we request you to add a
Loading history...
|
|||
37 | $hostname = null, |
||
0 ignored issues
–
show
|
|||
38 | $username = null, |
||
0 ignored issues
–
show
|
|||
39 | $password = null, |
||
0 ignored issues
–
show
|
|||
40 | $new = false, |
||
0 ignored issues
–
show
|
|||
41 | $flags = 0 |
||
42 | ) { |
||
0 ignored issues
–
show
|
|||
43 | 65 | if ($new !== false) { |
|
0 ignored issues
–
show
|
|||
44 | 1 | trigger_error('Argument $new is no longer supported in PHP > 7', E_USER_WARNING); |
|
0 ignored issues
–
show
|
|||
45 | } |
||
0 ignored issues
–
show
|
|||
46 | |||
47 | 64 | if (null === $hostname) { |
|
0 ignored issues
–
show
|
|||
48 | 1 | $hostname = ini_get('mysqli.default_host') ?: null; |
|
0 ignored issues
–
show
|
|||
49 | } |
||
0 ignored issues
–
show
|
|||
50 | 64 | if (null === $username) { |
|
0 ignored issues
–
show
|
|||
51 | 1 | $username = ini_get('mysqli.default_user') ?: null; |
|
0 ignored issues
–
show
|
|||
52 | } |
||
0 ignored issues
–
show
|
|||
53 | 64 | if (null === $password) { |
|
0 ignored issues
–
show
|
|||
54 | 61 | $password = ini_get('mysqli.default_pw') ?: null; |
|
0 ignored issues
–
show
|
|||
55 | } |
||
0 ignored issues
–
show
|
|||
56 | |||
57 | 64 | $socket = ''; |
|
0 ignored issues
–
show
|
|||
58 | 64 | if (strpos($hostname, ':/') === 0) { |
|
0 ignored issues
–
show
|
|||
59 | // it's a unix socket |
||
0 ignored issues
–
show
|
|||
60 | $socket = $hostname; |
||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 3 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues.
Loading history...
|
|||
61 | $hostname = 'localhost'; |
||
0 ignored issues
–
show
|
|||
62 | } |
||
0 ignored issues
–
show
|
|||
63 | |||
64 | 64 | $hash = sha1($hostname . $username . $flags); |
|
0 ignored issues
–
show
|
|||
65 | /* persistent connections start with p: */ |
||
0 ignored issues
–
show
|
|||
66 | /* don't use a cached link for those */ |
||
0 ignored issues
–
show
|
|||
67 | 64 | if ($hostname[1] !== ':' && isset(\Dshafik\MySQL::$connections[$hash])) { |
|
0 ignored issues
–
show
|
|||
68 | 10 | \Dshafik\MySQL::$last_connection = \Dshafik\MySQL::$connections[$hash]['conn']; |
|
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 17 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues.
Loading history...
|
|||
69 | 10 | \Dshafik\MySQL::$connections[$hash]['refcount'] += 1; |
|
0 ignored issues
–
show
|
|||
70 | 10 | return \Dshafik\MySQL::$connections[$hash]['conn']; |
|
0 ignored issues
–
show
|
|||
71 | } |
||
0 ignored issues
–
show
|
|||
72 | |||
73 | /* A custom port can be specified by appending the hostname with :{port} e.g. hostname:3307 */ |
||
0 ignored issues
–
show
|
|||
74 | 55 | if (preg_match('/^(.+):([\d]+)$/', $hostname, $port_matches) === 1 && $port_matches[1] !== "p") { |
|
0 ignored issues
–
show
The string literal
p does not require double quotes, as per coding-style, please use single quotes.
PHP provides two ways to mark string literals. Either with single quotes String literals in single quotes on the other hand are evaluated very literally and the only two
characters that needs escaping in the literal are the single quote itself ( Double quoted string literals may contain other variables or more complex escape sequences. <?php
$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";
print $doubleQuoted;
will print an indented: If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear. For more information on PHP string literals and available escape sequences see the PHP core documentation.
Loading history...
|
|||
75 | $hostname = $port_matches[1]; |
||
0 ignored issues
–
show
|
|||
76 | $port = (int) $port_matches[2]; |
||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 5 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues.
Loading history...
|
|||
77 | } else { |
||
0 ignored issues
–
show
|
|||
78 | 55 | $port = null; |
|
0 ignored issues
–
show
|
|||
79 | } |
||
0 ignored issues
–
show
|
|||
80 | |||
81 | /* No flags, means we can use mysqli_connect() */ |
||
0 ignored issues
–
show
|
|||
82 | 55 | if ($flags === 0) { |
|
0 ignored issues
–
show
|
|||
83 | 53 | $conn = mysqli_connect($hostname, $username, $password, '', $port); |
|
0 ignored issues
–
show
|
|||
84 | 52 | if (!$conn instanceof mysqli) { |
|
0 ignored issues
–
show
|
|||
85 | 1 | return false; |
|
0 ignored issues
–
show
|
|||
86 | } |
||
0 ignored issues
–
show
|
|||
87 | 51 | \Dshafik\MySQL::$last_connection = $conn; |
|
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 4 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues.
Loading history...
|
|||
88 | 51 | $conn->hash = $hash; |
|
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 25 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues.
Loading history...
|
|||
89 | 51 | \Dshafik\MySQL::$connections[$hash] = array('refcount' => 1, 'conn' => $conn); |
|
0 ignored issues
–
show
|
|||
90 | |||
91 | 51 | return $conn; |
|
0 ignored issues
–
show
|
|||
92 | } |
||
0 ignored issues
–
show
|
|||
93 | |||
94 | /* Flags means we need to use mysqli_real_connect() instead, and handle exceptions */ |
||
0 ignored issues
–
show
|
|||
95 | try { |
||
0 ignored issues
–
show
|
|||
96 | 2 | \Dshafik\MySQL::$last_connection = $conn = mysqli_init(); |
|
0 ignored issues
–
show
|
|||
97 | |||
98 | 2 | mysqli_real_connect( |
|
0 ignored issues
–
show
|
|||
99 | 2 | $conn, |
|
100 | 2 | $hostname, |
|
101 | 2 | $username, |
|
102 | 2 | $password, |
|
103 | 2 | '', |
|
104 | 2 | $port, |
|
105 | 2 | $socket, |
|
106 | 2 | $flags |
|
107 | ); |
||
108 | |||
109 | // @codeCoverageIgnoreStart |
||
0 ignored issues
–
show
|
|||
110 | // PHPUnit turns the warning from mysqli_real_connect into an exception, so this never runs |
||
0 ignored issues
–
show
|
|||
111 | if ($conn === false) { |
||
0 ignored issues
–
show
|
|||
112 | return false; |
||
0 ignored issues
–
show
|
|||
113 | } |
||
0 ignored issues
–
show
|
|||
114 | // @codeCoverageIgnoreEnd |
||
0 ignored issues
–
show
|
|||
115 | |||
116 | 1 | $conn->hash = $hash; |
|
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 25 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues.
Loading history...
|
|||
117 | 1 | \Dshafik\MySQL::$connections[$hash] = array('refcount' => 1, 'conn' => $conn); |
|
0 ignored issues
–
show
|
|||
118 | |||
119 | 1 | return $conn; |
|
0 ignored issues
–
show
|
|||
120 | 1 | } catch (\Throwable $e) { |
|
0 ignored issues
–
show
|
|||
121 | 1 | trigger_error($e->getMessage(), E_USER_WARNING); |
|
0 ignored issues
–
show
|
|||
122 | // @codeCoverageIgnoreStart |
||
0 ignored issues
–
show
|
|||
123 | // PHPUnit turns the warning into an exception, so this never runs |
||
0 ignored issues
–
show
|
|||
124 | return false; |
||
0 ignored issues
–
show
|
|||
125 | // @codeCoverageIgnoreEnd |
||
0 ignored issues
–
show
|
|||
126 | } |
||
0 ignored issues
–
show
|
|||
127 | } |
||
0 ignored issues
–
show
|
|||
128 | |||
129 | function mysql_pconnect( |
||
0 ignored issues
–
show
The return type could not be reliably inferred; please add a
@return annotation.
Our type inference engine in quite powerful, but sometimes the code does not
provide enough clues to go by. In these cases we request you to add a
Loading history...
|
|||
130 | $hostname = null, |
||
0 ignored issues
–
show
|
|||
131 | $username = null, |
||
0 ignored issues
–
show
|
|||
132 | $password = null, |
||
0 ignored issues
–
show
|
|||
133 | $flags = 0 |
||
134 | ) { |
||
0 ignored issues
–
show
|
|||
135 | 1 | $hostname = 'p:' . $hostname; |
|
0 ignored issues
–
show
|
|||
136 | 1 | return mysql_connect($hostname, $username, $password, false, $flags); |
|
0 ignored issues
–
show
|
|||
137 | } |
||
0 ignored issues
–
show
|
|||
138 | |||
139 | function mysql_close(\mysqli $link = null) |
||
0 ignored issues
–
show
|
|||
140 | { |
||
0 ignored issues
–
show
|
|||
141 | 89 | $isDefault = ($link === null); |
|
0 ignored issues
–
show
|
|||
142 | |||
143 | 89 | $link = \Dshafik\MySQL::getConnection($link, __FUNCTION__); |
|
0 ignored issues
–
show
|
|||
144 | 89 | if ($link === null) { |
|
0 ignored issues
–
show
|
|||
145 | // @codeCoverageIgnoreStart |
||
0 ignored issues
–
show
|
|||
146 | // PHPUnit Warning -> Exception |
||
0 ignored issues
–
show
|
|||
147 | return false; |
||
0 ignored issues
–
show
|
|||
148 | // @codeCoverageIgnoreEnd |
||
0 ignored issues
–
show
|
|||
149 | } |
||
0 ignored issues
–
show
|
|||
150 | |||
151 | 89 | if (isset(\Dshafik\MySQL::$connections[$link->hash])) { |
|
0 ignored issues
–
show
|
|||
152 | 61 | \Dshafik\MySQL::$connections[$link->hash]['refcount'] -= 1; |
|
0 ignored issues
–
show
|
|||
153 | } |
||
0 ignored issues
–
show
|
|||
154 | |||
155 | 89 | $return = true; |
|
0 ignored issues
–
show
|
|||
156 | 89 | if (\Dshafik\MySQL::$connections[$link->hash]['refcount'] === 0) { |
|
0 ignored issues
–
show
|
|||
157 | 52 | $return = mysqli_close($link); |
|
0 ignored issues
–
show
|
|||
158 | 52 | unset(\Dshafik\MySQL::$connections[$link->hash]); |
|
0 ignored issues
–
show
|
|||
159 | } |
||
0 ignored issues
–
show
|
|||
160 | |||
161 | 89 | if ($isDefault) { |
|
0 ignored issues
–
show
|
|||
162 | 89 | Dshafik\MySQL::$last_connection = null; |
|
0 ignored issues
–
show
|
|||
163 | } |
||
0 ignored issues
–
show
|
|||
164 | |||
165 | 89 | return $return; |
|
0 ignored issues
–
show
|
|||
166 | } |
||
0 ignored issues
–
show
|
|||
167 | |||
168 | function mysql_select_db($databaseName, \mysqli $link = null) |
||
0 ignored issues
–
show
|
|||
169 | { |
||
0 ignored issues
–
show
|
|||
170 | 54 | $link = \Dshafik\MySQL::getConnection($link); |
|
0 ignored issues
–
show
|
|||
171 | |||
172 | 54 | return mysqli_query( |
|
0 ignored issues
–
show
|
|||
173 | 54 | $link, |
|
174 | 54 | 'USE `' . mysqli_real_escape_string($link, $databaseName) . '`' |
|
175 | 54 | ) !== false; |
|
0 ignored issues
–
show
|
|||
176 | } |
||
0 ignored issues
–
show
|
|||
177 | |||
178 | function mysql_query($query, \mysqli $link = null) |
||
0 ignored issues
–
show
|
|||
179 | { |
||
0 ignored issues
–
show
|
|||
180 | 57 | return mysqli_query(\Dshafik\MySQL::getConnection($link), $query); |
|
0 ignored issues
–
show
|
|||
181 | } |
||
0 ignored issues
–
show
|
|||
182 | |||
183 | function mysql_unbuffered_query($query, \mysqli $link = null) |
||
0 ignored issues
–
show
|
|||
184 | { |
||
0 ignored issues
–
show
|
|||
185 | 4 | $link = \Dshafik\MySQL::getConnection($link); |
|
0 ignored issues
–
show
|
|||
186 | 4 | if (mysqli_real_query($link, $query)) { |
|
0 ignored issues
–
show
|
|||
187 | 3 | return mysqli_use_result($link); |
|
0 ignored issues
–
show
|
|||
188 | } |
||
0 ignored issues
–
show
|
|||
189 | |||
190 | 1 | return false; |
|
0 ignored issues
–
show
|
|||
191 | } |
||
0 ignored issues
–
show
|
|||
192 | |||
193 | function mysql_db_query($databaseName, $query, \mysqli $link = null) |
||
0 ignored issues
–
show
|
|||
194 | { |
||
0 ignored issues
–
show
|
|||
195 | 2 | if (mysql_select_db($databaseName, $link)) { |
|
0 ignored issues
–
show
|
|||
196 | 1 | return mysql_query($query, $link); |
|
0 ignored issues
–
show
|
|||
197 | } |
||
0 ignored issues
–
show
|
|||
198 | 1 | return false; |
|
0 ignored issues
–
show
|
|||
199 | } |
||
0 ignored issues
–
show
|
|||
200 | |||
201 | function mysql_list_dbs(\mysqli $link = null) |
||
0 ignored issues
–
show
|
|||
202 | { |
||
0 ignored issues
–
show
|
|||
203 | 2 | return mysql_query('SHOW DATABASES', $link); |
|
0 ignored issues
–
show
|
|||
204 | } |
||
0 ignored issues
–
show
|
|||
205 | |||
206 | function mysql_list_tables($databaseName, \mysqli $link = null) |
||
0 ignored issues
–
show
|
|||
207 | { |
||
0 ignored issues
–
show
|
|||
208 | 3 | $link = \Dshafik\MySQL::getConnection($link); |
|
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 2 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues.
Loading history...
|
|||
209 | 3 | $query = sprintf( |
|
0 ignored issues
–
show
|
|||
210 | 3 | 'SHOW TABLES FROM `%s`', |
|
211 | 3 | mysql_real_escape_string($databaseName, $link) |
|
212 | ); |
||
213 | 3 | return mysql_query($query, $link); |
|
0 ignored issues
–
show
|
|||
214 | } |
||
0 ignored issues
–
show
|
|||
215 | |||
216 | function mysql_list_fields($databaseName, $tableName, \mysqli $link = null) |
||
0 ignored issues
–
show
|
|||
217 | { |
||
0 ignored issues
–
show
|
|||
218 | 3 | $link = \Dshafik\MySQL::getConnection($link); |
|
0 ignored issues
–
show
|
|||
219 | |||
220 | 3 | $query = sprintf( |
|
0 ignored issues
–
show
|
|||
221 | 3 | 'SHOW COLUMNS FROM `%s`.`%s`', |
|
222 | 3 | mysqli_real_escape_string($link, $databaseName), |
|
223 | 3 | mysqli_real_escape_string($link, $tableName) |
|
224 | ); |
||
225 | |||
226 | 3 | $result = mysql_query($query, $link); |
|
0 ignored issues
–
show
|
|||
227 | |||
228 | 3 | if ($result instanceof \mysqli_result) { |
|
0 ignored issues
–
show
|
|||
229 | 2 | $result->table = $tableName; |
|
0 ignored issues
–
show
|
|||
230 | 2 | return $result; |
|
0 ignored issues
–
show
|
|||
231 | } |
||
0 ignored issues
–
show
|
|||
232 | |||
233 | 1 | trigger_error('mysql_list_fields(): Unable to save MySQL query result', E_USER_WARNING); |
|
0 ignored issues
–
show
|
|||
234 | // @codeCoverageIgnoreStart |
||
0 ignored issues
–
show
|
|||
235 | return false; |
||
0 ignored issues
–
show
|
|||
236 | // @codeCoverageIgnoreEnd |
||
0 ignored issues
–
show
|
|||
237 | } |
||
0 ignored issues
–
show
|
|||
238 | |||
239 | function mysql_list_processes(\mysqli $link = null) |
||
0 ignored issues
–
show
|
|||
240 | { |
||
0 ignored issues
–
show
|
|||
241 | return mysql_query('SHOW PROCESSLIST', $link); |
||
0 ignored issues
–
show
|
|||
242 | } |
||
0 ignored issues
–
show
|
|||
243 | |||
244 | function mysql_error(\mysqli $link = null) |
||
0 ignored issues
–
show
|
|||
245 | { |
||
0 ignored issues
–
show
|
|||
246 | 32 | return mysqli_error(\Dshafik\MySQL::getConnection($link)); |
|
0 ignored issues
–
show
|
|||
247 | } |
||
0 ignored issues
–
show
|
|||
248 | |||
249 | function mysql_errno(\mysqli $link = null) |
||
0 ignored issues
–
show
|
|||
250 | { |
||
0 ignored issues
–
show
|
|||
251 | 1 | return mysqli_errno(\Dshafik\MySQL::getConnection($link)); |
|
0 ignored issues
–
show
|
|||
252 | } |
||
0 ignored issues
–
show
|
|||
253 | |||
254 | function mysql_affected_rows(\mysqli $link = null) |
||
0 ignored issues
–
show
|
|||
255 | { |
||
0 ignored issues
–
show
|
|||
256 | 1 | return mysqli_affected_rows(\Dshafik\MySQL::getConnection($link)); |
|
0 ignored issues
–
show
|
|||
257 | } |
||
0 ignored issues
–
show
|
|||
258 | |||
259 | function mysql_insert_id($link = null) /*|*/ |
||
0 ignored issues
–
show
|
|||
260 | { |
||
0 ignored issues
–
show
|
|||
261 | 1 | return mysqli_insert_id(\Dshafik\MySQL::getConnection($link)); |
|
0 ignored issues
–
show
|
|||
262 | } |
||
0 ignored issues
–
show
|
|||
263 | |||
264 | function mysql_result($result, $row, $field = 0) |
||
0 ignored issues
–
show
The return type could not be reliably inferred; please add a
@return annotation.
Our type inference engine in quite powerful, but sometimes the code does not
provide enough clues to go by. In these cases we request you to add a
Loading history...
|
|||
265 | { |
||
0 ignored issues
–
show
|
|||
266 | 8 | if (!\Dshafik\MySQL::checkValidResult($result, __FUNCTION__)) { |
|
0 ignored issues
–
show
|
|||
267 | // @codeCoverageIgnoreStart |
||
0 ignored issues
–
show
|
|||
268 | return false; |
||
0 ignored issues
–
show
|
|||
269 | // @codeCoverageIgnoreEnd |
||
0 ignored issues
–
show
|
|||
270 | } |
||
0 ignored issues
–
show
|
|||
271 | |||
272 | 7 | if (!mysqli_data_seek($result, $row)) { |
|
0 ignored issues
–
show
|
|||
273 | 1 | trigger_error( |
|
0 ignored issues
–
show
|
|||
274 | 1 | sprintf( |
|
275 | 1 | 'mysql_result(): Unable to jump to row %d on MySQL result index %s', |
|
276 | 1 | $row, |
|
277 | 1 | spl_object_hash($result) |
|
278 | ), |
||
279 | 1 | E_USER_WARNING |
|
280 | ); |
||
281 | // @codeCoverageIgnoreStart |
||
0 ignored issues
–
show
|
|||
282 | return false; |
||
0 ignored issues
–
show
|
|||
283 | // @codeCoverageIgnoreEnd |
||
0 ignored issues
–
show
|
|||
284 | } |
||
0 ignored issues
–
show
|
|||
285 | |||
286 | 6 | $found = true; |
|
0 ignored issues
–
show
|
|||
287 | 6 | if (strpos($field, '.') !== false) { |
|
0 ignored issues
–
show
|
|||
288 | 3 | list($table, $name) = explode('.', $field); |
|
0 ignored issues
–
show
|
|||
289 | 3 | $i = 0; |
|
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 18 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues.
Loading history...
|
|||
290 | 3 | $found = false; |
|
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 14 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues.
Loading history...
|
|||
291 | 3 | mysqli_field_seek($result, 0); |
|
0 ignored issues
–
show
|
|||
292 | 3 | while ($column = mysqli_fetch_field($result)) { |
|
0 ignored issues
–
show
|
|||
293 | 3 | if ($column->table === $table && $column->name === $name) { |
|
0 ignored issues
–
show
|
|||
294 | 2 | $field = $i; |
|
0 ignored issues
–
show
|
|||
295 | 2 | $found = true; |
|
0 ignored issues
–
show
|
|||
296 | 2 | break; |
|
0 ignored issues
–
show
|
|||
297 | } |
||
0 ignored issues
–
show
|
|||
298 | 3 | $i++; |
|
0 ignored issues
–
show
|
|||
299 | } |
||
0 ignored issues
–
show
|
|||
300 | } |
||
0 ignored issues
–
show
|
|||
301 | |||
302 | 6 | $row = mysql_fetch_array($result); |
|
0 ignored issues
–
show
|
|||
303 | 6 | if ($found && array_key_exists($field, $row)) { |
|
0 ignored issues
–
show
|
|||
304 | 4 | return $row[$field]; |
|
0 ignored issues
–
show
|
|||
305 | } |
||
0 ignored issues
–
show
|
|||
306 | |||
307 | 2 | trigger_error( |
|
0 ignored issues
–
show
|
|||
308 | 2 | sprintf( |
|
309 | 2 | '%s(): %s not found in MySQL result index %s', |
|
310 | 2 | __FUNCTION__, |
|
311 | 2 | $field, |
|
312 | 2 | spl_object_hash($result) |
|
313 | ), |
||
314 | 2 | E_USER_WARNING |
|
315 | ); |
||
316 | // @codeCoverageIgnoreStart |
||
0 ignored issues
–
show
|
|||
317 | return false; |
||
0 ignored issues
–
show
|
|||
318 | // @codeCoverageIgnoreEnd |
||
0 ignored issues
–
show
|
|||
319 | } |
||
0 ignored issues
–
show
|
|||
320 | |||
321 | function mysql_num_rows($result) |
||
0 ignored issues
–
show
|
|||
322 | { |
||
0 ignored issues
–
show
|
|||
323 | 14 | if (!\Dshafik\MySQL::checkValidResult($result, __FUNCTION__)) { |
|
0 ignored issues
–
show
|
|||
324 | // @codeCoverageIgnoreStart |
||
0 ignored issues
–
show
|
|||
325 | return false; |
||
0 ignored issues
–
show
|
|||
326 | // @codeCoverageIgnoreEnd |
||
0 ignored issues
–
show
|
|||
327 | } |
||
0 ignored issues
–
show
|
|||
328 | |||
329 | 13 | $previous = error_reporting(0); |
|
0 ignored issues
–
show
|
|||
330 | 13 | $rows = mysqli_num_rows($result); |
|
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 5 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues.
Loading history...
|
|||
331 | 13 | error_reporting($previous); |
|
0 ignored issues
–
show
|
|||
332 | |||
333 | 13 | return $rows; |
|
0 ignored issues
–
show
|
|||
334 | } |
||
0 ignored issues
–
show
|
|||
335 | |||
336 | function mysql_num_fields($result) |
||
0 ignored issues
–
show
|
|||
337 | { |
||
0 ignored issues
–
show
|
|||
338 | 3 | if (!\Dshafik\MySQL::checkValidResult($result, __FUNCTION__)) { |
|
0 ignored issues
–
show
|
|||
339 | // @codeCoverageIgnoreStart |
||
0 ignored issues
–
show
|
|||
340 | return false; |
||
0 ignored issues
–
show
|
|||
341 | // @codeCoverageIgnoreEnd |
||
0 ignored issues
–
show
|
|||
342 | } |
||
0 ignored issues
–
show
|
|||
343 | 1 | return mysqli_num_fields($result); |
|
0 ignored issues
–
show
|
|||
344 | } |
||
0 ignored issues
–
show
|
|||
345 | |||
346 | function mysql_fetch_row($result) |
||
0 ignored issues
–
show
|
|||
347 | { |
||
0 ignored issues
–
show
|
|||
348 | 6 | if (!\Dshafik\MySQL::checkValidResult($result, __FUNCTION__)) { |
|
0 ignored issues
–
show
|
|||
349 | // @codeCoverageIgnoreStart |
||
0 ignored issues
–
show
|
|||
350 | return false; |
||
0 ignored issues
–
show
|
|||
351 | // @codeCoverageIgnoreEnd |
||
0 ignored issues
–
show
|
|||
352 | } |
||
0 ignored issues
–
show
|
|||
353 | 5 | return mysqli_fetch_row($result) ?: false; |
|
0 ignored issues
–
show
|
|||
354 | } |
||
0 ignored issues
–
show
|
|||
355 | |||
356 | function mysql_fetch_array($result, $resultType = MYSQL_BOTH) |
||
0 ignored issues
–
show
|
|||
357 | { |
||
0 ignored issues
–
show
|
|||
358 | 11 | if (!\Dshafik\MySQL::checkValidResult($result, __FUNCTION__)) { |
|
0 ignored issues
–
show
|
|||
359 | // @codeCoverageIgnoreStart |
||
0 ignored issues
–
show
|
|||
360 | return false; |
||
0 ignored issues
–
show
|
|||
361 | // @codeCoverageIgnoreEnd |
||
0 ignored issues
–
show
|
|||
362 | } |
||
0 ignored issues
–
show
|
|||
363 | 10 | return mysqli_fetch_array($result, $resultType) ?: false; |
|
0 ignored issues
–
show
|
|||
364 | } |
||
0 ignored issues
–
show
|
|||
365 | |||
366 | function mysql_fetch_assoc($result) /* : array|null */ |
||
0 ignored issues
–
show
80% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them.
Loading history...
|
|||
367 | { |
||
0 ignored issues
–
show
|
|||
368 | 9 | if (!\Dshafik\MySQL::checkValidResult($result, __FUNCTION__)) { |
|
0 ignored issues
–
show
|
|||
369 | // @codeCoverageIgnoreStart |
||
0 ignored issues
–
show
|
|||
370 | return false; |
||
0 ignored issues
–
show
|
|||
371 | // @codeCoverageIgnoreEnd |
||
0 ignored issues
–
show
|
|||
372 | } |
||
0 ignored issues
–
show
|
|||
373 | |||
374 | 8 | return mysqli_fetch_assoc($result) ?: false; |
|
0 ignored issues
–
show
|
|||
375 | } |
||
0 ignored issues
–
show
|
|||
376 | |||
377 | function mysql_fetch_object($result, $class = null, array $params = array()) /* : object|null */ |
||
0 ignored issues
–
show
60% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them.
Loading history...
|
|||
378 | { |
||
0 ignored issues
–
show
|
|||
379 | 3 | if (!\Dshafik\MySQL::checkValidResult($result, __FUNCTION__)) { |
|
0 ignored issues
–
show
|
|||
380 | // @codeCoverageIgnoreStart |
||
0 ignored issues
–
show
|
|||
381 | return false; |
||
0 ignored issues
–
show
|
|||
382 | // @codeCoverageIgnoreEnd |
||
0 ignored issues
–
show
|
|||
383 | } |
||
0 ignored issues
–
show
|
|||
384 | |||
385 | 2 | if ($class === null) { |
|
0 ignored issues
–
show
|
|||
386 | 2 | $object = mysqli_fetch_object($result); |
|
0 ignored issues
–
show
|
|||
387 | } else { |
||
0 ignored issues
–
show
|
|||
388 | $object = mysqli_fetch_object($result, $class, $params); |
||
0 ignored issues
–
show
|
|||
389 | } |
||
0 ignored issues
–
show
|
|||
390 | |||
391 | 2 | return $object ?: false; |
|
0 ignored issues
–
show
|
|||
392 | } |
||
0 ignored issues
–
show
|
|||
393 | |||
394 | function mysql_data_seek($result, $offset) |
||
0 ignored issues
–
show
|
|||
395 | { |
||
0 ignored issues
–
show
|
|||
396 | 1 | if (!\Dshafik\MySQL::checkValidResult($result, __FUNCTION__)) { |
|
0 ignored issues
–
show
|
|||
397 | // @codeCoverageIgnoreStart |
||
0 ignored issues
–
show
|
|||
398 | return false; |
||
0 ignored issues
–
show
|
|||
399 | // @codeCoverageIgnoreEnd |
||
0 ignored issues
–
show
|
|||
400 | } |
||
0 ignored issues
–
show
|
|||
401 | return mysqli_data_seek($result, $offset); |
||
0 ignored issues
–
show
|
|||
402 | } |
||
0 ignored issues
–
show
|
|||
403 | |||
404 | function mysql_fetch_lengths($result) /* : array|*/ |
||
0 ignored issues
–
show
75% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them.
Loading history...
|
|||
405 | { |
||
0 ignored issues
–
show
|
|||
406 | 1 | if (!\Dshafik\MySQL::checkValidResult($result, __FUNCTION__)) { |
|
0 ignored issues
–
show
|
|||
407 | // @codeCoverageIgnoreStart |
||
0 ignored issues
–
show
|
|||
408 | return false; |
||
0 ignored issues
–
show
|
|||
409 | // @codeCoverageIgnoreEnd |
||
0 ignored issues
–
show
|
|||
410 | } |
||
0 ignored issues
–
show
|
|||
411 | return mysqli_fetch_lengths($result); |
||
0 ignored issues
–
show
|
|||
412 | } |
||
0 ignored issues
–
show
|
|||
413 | |||
414 | function mysql_fetch_field($result) /* : object|*/ |
||
0 ignored issues
–
show
50% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them.
Loading history...
|
|||
415 | { |
||
0 ignored issues
–
show
|
|||
416 | 4 | if (!\Dshafik\MySQL::checkValidResult($result, __FUNCTION__)) { |
|
0 ignored issues
–
show
|
|||
417 | // @codeCoverageIgnoreStart |
||
0 ignored issues
–
show
|
|||
418 | return false; |
||
0 ignored issues
–
show
|
|||
419 | // @codeCoverageIgnoreEnd |
||
0 ignored issues
–
show
|
|||
420 | } |
||
0 ignored issues
–
show
|
|||
421 | 2 | $res = mysqli_fetch_field($result); |
|
0 ignored issues
–
show
|
|||
422 | 2 | if ($res instanceof \stdClass) { |
|
0 ignored issues
–
show
|
|||
423 | 2 | $res->not_null = ($res->flags & MYSQLI_NOT_NULL_FLAG) ? 1 : 0; |
|
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 5 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues.
Loading history...
|
|||
424 | 2 | $res->primary_key = ($res->flags & MYSQLI_PRI_KEY_FLAG ) ? 1 : 0; |
|
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 2 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues.
Loading history...
|
|||
425 | 2 | $res->unique_key = ($res->flags & MYSQLI_UNIQUE_KEY_FLAG ) ? 1 : 0; |
|
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 3 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues.
Loading history...
|
|||
426 | 2 | $res->multiple_key = ($res->flags & MYSQLI_MULTIPLE_KEY_FLAG ) ? 1 : 0; |
|
0 ignored issues
–
show
|
|||
427 | 2 | $res->numeric = ($res->flags & MYSQLI_NUM_FLAG ) ? 1 : 0; |
|
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 6 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues.
Loading history...
|
|||
428 | 2 | $res->blob = ($res->flags & MYSQLI_BLOB_FLAG ) ? 1 : 0; |
|
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 9 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues.
Loading history...
|
|||
429 | 2 | $res->unsigned = ($res->flags & MYSQLI_UNSIGNED_FLAG ) ? 1 : 0; |
|
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 5 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues.
Loading history...
|
|||
430 | 2 | $res->zerofill = ($res->flags & MYSQLI_ZEROFILL_FLAG ) ? 1 : 0; |
|
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 5 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues.
Loading history...
|
|||
431 | } |
||
0 ignored issues
–
show
|
|||
432 | 2 | return $res; |
|
0 ignored issues
–
show
|
|||
433 | } |
||
0 ignored issues
–
show
|
|||
434 | |||
435 | function mysql_field_seek($result, $field) |
||
0 ignored issues
–
show
|
|||
436 | { |
||
0 ignored issues
–
show
|
|||
437 | 1 | if (!\Dshafik\MySQL::checkValidResult($result, __FUNCTION__)) { |
|
0 ignored issues
–
show
|
|||
438 | // @codeCoverageIgnoreStart |
||
0 ignored issues
–
show
|
|||
439 | return false; |
||
0 ignored issues
–
show
|
|||
440 | // @codeCoverageIgnoreEnd |
||
0 ignored issues
–
show
|
|||
441 | } |
||
0 ignored issues
–
show
|
|||
442 | return mysqli_field_seek($result, $field); |
||
0 ignored issues
–
show
|
|||
443 | } |
||
0 ignored issues
–
show
|
|||
444 | |||
445 | function mysql_free_result($result) |
||
0 ignored issues
–
show
|
|||
446 | { |
||
0 ignored issues
–
show
|
|||
447 | 2 | if (!\Dshafik\MySQL::checkValidResult($result, __FUNCTION__)) { |
|
0 ignored issues
–
show
|
|||
448 | // @codeCoverageIgnoreStart |
||
0 ignored issues
–
show
|
|||
449 | return false; |
||
0 ignored issues
–
show
|
|||
450 | // @codeCoverageIgnoreEnd |
||
0 ignored issues
–
show
|
|||
451 | } |
||
0 ignored issues
–
show
|
|||
452 | 1 | return mysqli_free_result($result); |
|
0 ignored issues
–
show
|
|||
453 | } |
||
0 ignored issues
–
show
|
|||
454 | |||
455 | View Code Duplication | function mysql_field_name($result, $field) |
|
0 ignored issues
–
show
The return type could not be reliably inferred; please add a
@return annotation.
Our type inference engine in quite powerful, but sometimes the code does not
provide enough clues to go by. In these cases we request you to add a
Loading history...
|
|||
456 | { |
||
0 ignored issues
–
show
|
|||
457 | 4 | if (!\Dshafik\MySQL::checkValidResult($result, __FUNCTION__)) { |
|
0 ignored issues
–
show
|
|||
458 | // @codeCoverageIgnoreStart |
||
0 ignored issues
–
show
|
|||
459 | return false; |
||
0 ignored issues
–
show
|
|||
460 | // @codeCoverageIgnoreEnd |
||
0 ignored issues
–
show
|
|||
461 | } |
||
0 ignored issues
–
show
|
|||
462 | 3 | return \Dshafik\MySQL::mysqlFieldInfo($result, $field, 'name'); |
|
0 ignored issues
–
show
|
|||
463 | } |
||
0 ignored issues
–
show
|
|||
464 | |||
465 | function mysql_field_table($result, $field) |
||
0 ignored issues
–
show
The return type could not be reliably inferred; please add a
@return annotation.
Our type inference engine in quite powerful, but sometimes the code does not
provide enough clues to go by. In these cases we request you to add a
Loading history...
|
|||
466 | { |
||
0 ignored issues
–
show
|
|||
467 | 4 | if (!\Dshafik\MySQL::checkValidResult($result, __FUNCTION__)) { |
|
0 ignored issues
–
show
|
|||
468 | // @codeCoverageIgnoreStart |
||
0 ignored issues
–
show
|
|||
469 | return false; |
||
0 ignored issues
–
show
|
|||
470 | // @codeCoverageIgnoreEnd |
||
0 ignored issues
–
show
|
|||
471 | } |
||
0 ignored issues
–
show
|
|||
472 | 3 | return \Dshafik\MySQL::mysqlFieldInfo($result, $field, 'table'); |
|
0 ignored issues
–
show
|
|||
473 | } |
||
0 ignored issues
–
show
|
|||
474 | |||
475 | function mysql_field_len($result, $field) |
||
0 ignored issues
–
show
The return type could not be reliably inferred; please add a
@return annotation.
Our type inference engine in quite powerful, but sometimes the code does not
provide enough clues to go by. In these cases we request you to add a
Loading history...
|
|||
476 | { |
||
0 ignored issues
–
show
|
|||
477 | 4 | if (!\Dshafik\MySQL::checkValidResult($result, __FUNCTION__)) { |
|
0 ignored issues
–
show
|
|||
478 | // @codeCoverageIgnoreStart |
||
0 ignored issues
–
show
|
|||
479 | return false; |
||
0 ignored issues
–
show
|
|||
480 | // @codeCoverageIgnoreEnd |
||
0 ignored issues
–
show
|
|||
481 | } |
||
0 ignored issues
–
show
|
|||
482 | 3 | return \Dshafik\MySQL::mysqlFieldInfo($result, $field, 'length'); |
|
0 ignored issues
–
show
|
|||
483 | } |
||
0 ignored issues
–
show
|
|||
484 | |||
485 | View Code Duplication | function mysql_field_type($result, $field) |
|
0 ignored issues
–
show
The return type could not be reliably inferred; please add a
@return annotation.
Our type inference engine in quite powerful, but sometimes the code does not
provide enough clues to go by. In these cases we request you to add a
Loading history...
|
|||
486 | { |
||
0 ignored issues
–
show
|
|||
487 | 4 | if (!\Dshafik\MySQL::checkValidResult($result, __FUNCTION__)) { |
|
0 ignored issues
–
show
|
|||
488 | // @codeCoverageIgnoreStart |
||
0 ignored issues
–
show
|
|||
489 | return false; |
||
0 ignored issues
–
show
|
|||
490 | // @codeCoverageIgnoreEnd |
||
0 ignored issues
–
show
|
|||
491 | } |
||
0 ignored issues
–
show
|
|||
492 | 3 | return \Dshafik\MySQL::mysqlFieldInfo($result, $field, 'type'); |
|
0 ignored issues
–
show
|
|||
493 | } |
||
0 ignored issues
–
show
|
|||
494 | |||
495 | function mysql_field_flags($result, $field) |
||
0 ignored issues
–
show
The return type could not be reliably inferred; please add a
@return annotation.
Our type inference engine in quite powerful, but sometimes the code does not
provide enough clues to go by. In these cases we request you to add a
Loading history...
|
|||
496 | { |
||
0 ignored issues
–
show
|
|||
497 | 4 | if (!\Dshafik\MySQL::checkValidResult($result, __FUNCTION__)) { |
|
0 ignored issues
–
show
|
|||
498 | // @codeCoverageIgnoreStart |
||
0 ignored issues
–
show
|
|||
499 | return false; |
||
0 ignored issues
–
show
|
|||
500 | // @codeCoverageIgnoreEnd |
||
0 ignored issues
–
show
|
|||
501 | } |
||
0 ignored issues
–
show
|
|||
502 | 3 | return \Dshafik\MySQL::mysqlFieldInfo($result, $field, 'flags'); |
|
0 ignored issues
–
show
|
|||
503 | } |
||
0 ignored issues
–
show
|
|||
504 | |||
505 | function mysql_escape_string($unescapedString) |
||
0 ignored issues
–
show
The return type could not be reliably inferred; please add a
@return annotation.
Our type inference engine in quite powerful, but sometimes the code does not
provide enough clues to go by. In these cases we request you to add a
Loading history...
|
|||
506 | { |
||
0 ignored issues
–
show
|
|||
507 | 2 | if (\Dshafik\MySQL::$last_connection === null) { |
|
0 ignored issues
–
show
|
|||
508 | 2 | trigger_error( |
|
0 ignored issues
–
show
|
|||
509 | 2 | sprintf( |
|
510 | 2 | '%s() is insecure; use mysql_real_escape_string() instead!', |
|
511 | 2 | __FUNCTION__ |
|
512 | ), |
||
513 | 2 | E_USER_NOTICE |
|
514 | ); |
||
515 | |||
516 | 1 | return \Dshafik\MySQL::escapeString($unescapedString); |
|
0 ignored issues
–
show
|
|||
517 | } |
||
0 ignored issues
–
show
|
|||
518 | return mysql_real_escape_string($unescapedString, null); |
||
0 ignored issues
–
show
|
|||
519 | } |
||
0 ignored issues
–
show
|
|||
520 | |||
521 | function mysql_real_escape_string($unescapedString, \mysqli $link = null) |
||
0 ignored issues
–
show
The return type could not be reliably inferred; please add a
@return annotation.
Our type inference engine in quite powerful, but sometimes the code does not
provide enough clues to go by. In these cases we request you to add a
Loading history...
|
|||
522 | { |
||
0 ignored issues
–
show
|
|||
523 | 3 | return mysqli_escape_string(\Dshafik\MySQL::getConnection($link), $unescapedString); |
|
0 ignored issues
–
show
|
|||
524 | } |
||
0 ignored issues
–
show
|
|||
525 | |||
526 | function mysql_stat(\mysqli $link = null) |
||
0 ignored issues
–
show
|
|||
527 | { |
||
0 ignored issues
–
show
|
|||
528 | return mysqli_stat(\Dshafik\MySQL::getConnection($link)); |
||
0 ignored issues
–
show
|
|||
529 | } |
||
0 ignored issues
–
show
|
|||
530 | |||
531 | function mysql_thread_id(\mysqli $link = null) |
||
0 ignored issues
–
show
|
|||
532 | { |
||
0 ignored issues
–
show
|
|||
533 | return mysqli_thread_id(\Dshafik\MySQL::getConnection($link)); |
||
0 ignored issues
–
show
|
|||
534 | } |
||
0 ignored issues
–
show
|
|||
535 | |||
536 | function mysql_client_encoding(\mysqli $link = null) |
||
0 ignored issues
–
show
|
|||
537 | { |
||
0 ignored issues
–
show
|
|||
538 | return mysqli_character_set_name(\Dshafik\MySQL::getConnection($link)); |
||
0 ignored issues
–
show
|
|||
539 | } |
||
0 ignored issues
–
show
|
|||
540 | |||
541 | function mysql_ping(\mysqli $link = null) |
||
0 ignored issues
–
show
|
|||
542 | { |
||
0 ignored issues
–
show
|
|||
543 | return mysqli_ping(\Dshafik\MySQL::getConnection($link)); |
||
0 ignored issues
–
show
|
|||
544 | } |
||
0 ignored issues
–
show
|
|||
545 | |||
546 | function mysql_get_client_info(\mysqli $link = null) |
||
0 ignored issues
–
show
|
|||
547 | { |
||
0 ignored issues
–
show
|
|||
548 | return mysqli_get_client_info(\Dshafik\MySQL::getConnection($link)); |
||
0 ignored issues
–
show
|
|||
549 | } |
||
0 ignored issues
–
show
|
|||
550 | |||
551 | function mysql_get_host_info(\mysqli $link = null) |
||
0 ignored issues
–
show
The return type could not be reliably inferred; please add a
@return annotation.
Our type inference engine in quite powerful, but sometimes the code does not
provide enough clues to go by. In these cases we request you to add a
Loading history...
|
|||
552 | { |
||
0 ignored issues
–
show
|
|||
553 | return mysqli_get_host_info(\Dshafik\MySQL::getConnection($link)); |
||
0 ignored issues
–
show
|
|||
554 | } |
||
0 ignored issues
–
show
|
|||
555 | |||
556 | function mysql_get_proto_info(\mysqli $link = null) |
||
0 ignored issues
–
show
|
|||
557 | { |
||
0 ignored issues
–
show
|
|||
558 | return mysqli_get_proto_info(\Dshafik\MySQL::getConnection($link)); |
||
0 ignored issues
–
show
|
|||
559 | } |
||
0 ignored issues
–
show
|
|||
560 | |||
561 | function mysql_get_server_info(\mysqli $link = null) |
||
0 ignored issues
–
show
|
|||
562 | { |
||
0 ignored issues
–
show
|
|||
563 | return mysqli_get_server_info(\Dshafik\MySQL::getConnection($link)); |
||
0 ignored issues
–
show
|
|||
564 | } |
||
0 ignored issues
–
show
|
|||
565 | |||
566 | function mysql_info(\mysqli $link = null) |
||
0 ignored issues
–
show
|
|||
567 | { |
||
0 ignored issues
–
show
|
|||
568 | return mysqli_info(\Dshafik\MySQL::getConnection($link)); |
||
0 ignored issues
–
show
|
|||
569 | } |
||
0 ignored issues
–
show
|
|||
570 | |||
571 | function mysql_set_charset($charset, \mysqli $link = null) |
||
0 ignored issues
–
show
|
|||
572 | { |
||
0 ignored issues
–
show
|
|||
573 | return mysqli_set_charset(\Dshafik\MySQL::getConnection($link), $charset); |
||
0 ignored issues
–
show
|
|||
574 | } |
||
0 ignored issues
–
show
|
|||
575 | |||
576 | function mysql_db_name($result, $row, $field = 0) |
||
0 ignored issues
–
show
The return type could not be reliably inferred; please add a
@return annotation.
Our type inference engine in quite powerful, but sometimes the code does not
provide enough clues to go by. In these cases we request you to add a
Loading history...
|
|||
577 | { |
||
0 ignored issues
–
show
|
|||
578 | 2 | if (!\Dshafik\MySQL::checkValidResult($result, __FUNCTION__)) { |
|
0 ignored issues
–
show
|
|||
579 | // @codeCoverageIgnoreStart |
||
0 ignored issues
–
show
|
|||
580 | return false; |
||
0 ignored issues
–
show
|
|||
581 | // @codeCoverageIgnoreEnd |
||
0 ignored issues
–
show
|
|||
582 | } |
||
0 ignored issues
–
show
|
|||
583 | |||
584 | // Alias as per https://github.com/php/php-src/blob/PHP-5.6/ext/mysql/php_mysql.c#L319 |
||
0 ignored issues
–
show
|
|||
585 | 1 | return mysql_result($result, $row, $field); |
|
0 ignored issues
–
show
|
|||
586 | } |
||
0 ignored issues
–
show
|
|||
587 | |||
588 | function mysql_tablename($result, $row) |
||
0 ignored issues
–
show
The return type could not be reliably inferred; please add a
@return annotation.
Our type inference engine in quite powerful, but sometimes the code does not
provide enough clues to go by. In these cases we request you to add a
Loading history...
|
|||
589 | { |
||
0 ignored issues
–
show
|
|||
590 | 1 | if (!\Dshafik\MySQL::checkValidResult($result, __FUNCTION__)) { |
|
0 ignored issues
–
show
|
|||
591 | // @codeCoverageIgnoreStart |
||
0 ignored issues
–
show
|
|||
592 | return false; |
||
0 ignored issues
–
show
|
|||
593 | // @codeCoverageIgnoreEnd |
||
0 ignored issues
–
show
|
|||
594 | } |
||
0 ignored issues
–
show
|
|||
595 | |||
596 | // Alias as per http://lxr.php.net/xref/PHP_5_6/ext/mysql/php_mysql.c#321 |
||
0 ignored issues
–
show
|
|||
597 | return mysql_result($result, $row, 'Table'); |
||
0 ignored issues
–
show
|
|||
598 | } |
||
0 ignored issues
–
show
|
|||
599 | |||
600 | /* Aliases */ |
||
0 ignored issues
–
show
|
|||
601 | |||
602 | function mysql_fieldname($result, $field) |
||
0 ignored issues
–
show
The return type could not be reliably inferred; please add a
@return annotation.
Our type inference engine in quite powerful, but sometimes the code does not
provide enough clues to go by. In these cases we request you to add a
Loading history...
|
|||
603 | { |
||
0 ignored issues
–
show
|
|||
604 | return mysql_field_name($result, $field); |
||
0 ignored issues
–
show
|
|||
605 | } |
||
0 ignored issues
–
show
|
|||
606 | |||
607 | function mysql_fieldtable($result, $field) |
||
0 ignored issues
–
show
The return type could not be reliably inferred; please add a
@return annotation.
Our type inference engine in quite powerful, but sometimes the code does not
provide enough clues to go by. In these cases we request you to add a
Loading history...
|
|||
608 | { |
||
0 ignored issues
–
show
|
|||
609 | return mysql_field_table($result, $field); |
||
0 ignored issues
–
show
|
|||
610 | } |
||
0 ignored issues
–
show
|
|||
611 | |||
612 | function mysql_fieldlen($result, $field) |
||
0 ignored issues
–
show
The return type could not be reliably inferred; please add a
@return annotation.
Our type inference engine in quite powerful, but sometimes the code does not
provide enough clues to go by. In these cases we request you to add a
Loading history...
|
|||
613 | { |
||
0 ignored issues
–
show
|
|||
614 | return mysql_field_len($result, $field); |
||
0 ignored issues
–
show
|
|||
615 | } |
||
0 ignored issues
–
show
|
|||
616 | |||
617 | function mysql_fieldtype($result, $field) |
||
0 ignored issues
–
show
The return type could not be reliably inferred; please add a
@return annotation.
Our type inference engine in quite powerful, but sometimes the code does not
provide enough clues to go by. In these cases we request you to add a
Loading history...
|
|||
618 | { |
||
0 ignored issues
–
show
|
|||
619 | return mysql_field_type($result, $field); |
||
0 ignored issues
–
show
|
|||
620 | } |
||
0 ignored issues
–
show
|
|||
621 | |||
622 | function mysql_fieldflags($result, $field) |
||
0 ignored issues
–
show
The return type could not be reliably inferred; please add a
@return annotation.
Our type inference engine in quite powerful, but sometimes the code does not
provide enough clues to go by. In these cases we request you to add a
Loading history...
|
|||
623 | { |
||
0 ignored issues
–
show
|
|||
624 | return mysql_field_flags($result, $field); |
||
0 ignored issues
–
show
|
|||
625 | } |
||
0 ignored issues
–
show
|
|||
626 | |||
627 | function mysql_selectdb($databaseName, $link = null) |
||
0 ignored issues
–
show
|
|||
628 | { |
||
0 ignored issues
–
show
|
|||
629 | return mysql_select_db($databaseName, $link); |
||
0 ignored issues
–
show
|
|||
630 | } |
||
0 ignored issues
–
show
|
|||
631 | |||
632 | function mysql_freeresult($result) |
||
0 ignored issues
–
show
|
|||
633 | { |
||
0 ignored issues
–
show
|
|||
634 | return mysql_free_result($result); |
||
0 ignored issues
–
show
|
|||
635 | } |
||
0 ignored issues
–
show
|
|||
636 | |||
637 | function mysql_numfields($result) |
||
0 ignored issues
–
show
|
|||
638 | { |
||
0 ignored issues
–
show
|
|||
639 | return mysql_num_fields($result); |
||
0 ignored issues
–
show
|
|||
640 | } |
||
0 ignored issues
–
show
|
|||
641 | |||
642 | function mysql_numrows($result) |
||
0 ignored issues
–
show
|
|||
643 | { |
||
0 ignored issues
–
show
|
|||
644 | return mysql_num_rows($result); |
||
0 ignored issues
–
show
|
|||
645 | } |
||
0 ignored issues
–
show
|
|||
646 | |||
647 | function mysql_listdbs($link) |
||
0 ignored issues
–
show
|
|||
648 | { |
||
0 ignored issues
–
show
|
|||
649 | return mysql_list_dbs($link); |
||
0 ignored issues
–
show
|
|||
650 | } |
||
0 ignored issues
–
show
|
|||
651 | |||
652 | function mysql_listtables($databaseName, $link = null) |
||
0 ignored issues
–
show
|
|||
653 | { |
||
0 ignored issues
–
show
|
|||
654 | return mysql_list_tables($databaseName, $link); |
||
0 ignored issues
–
show
|
|||
655 | } |
||
0 ignored issues
–
show
|
|||
656 | |||
657 | function mysql_listfields($databaseName, $tableName, $link = null) |
||
0 ignored issues
–
show
|
|||
658 | { |
||
0 ignored issues
–
show
|
|||
659 | return mysql_list_fields($databaseName, $tableName, $link); |
||
0 ignored issues
–
show
|
|||
660 | } |
||
0 ignored issues
–
show
|
|||
661 | |||
662 | function mysql_dbname($result, $row, $field = 0) |
||
0 ignored issues
–
show
The return type could not be reliably inferred; please add a
@return annotation.
Our type inference engine in quite powerful, but sometimes the code does not
provide enough clues to go by. In these cases we request you to add a
Loading history...
|
|||
663 | { |
||
0 ignored issues
–
show
|
|||
664 | return mysql_db_name($result, $row, $field); |
||
0 ignored issues
–
show
|
|||
665 | } |
||
0 ignored issues
–
show
|
|||
666 | |||
667 | function mysql_table_name($result, $row) |
||
0 ignored issues
–
show
The return type could not be reliably inferred; please add a
@return annotation.
Our type inference engine in quite powerful, but sometimes the code does not
provide enough clues to go by. In these cases we request you to add a
Loading history...
|
|||
668 | { |
||
0 ignored issues
–
show
|
|||
669 | return mysql_tablename($result, $row); |
||
0 ignored issues
–
show
|
|||
670 | } |
||
0 ignored issues
–
show
|
|||
671 | } |
||
0 ignored issues
–
show
|
|||
672 | } |
||
673 | |||
674 | namespace Dshafik { |
||
675 | |||
676 | class MySQL |
||
0 ignored issues
–
show
|
|||
677 | { |
||
0 ignored issues
–
show
|
|||
678 | public static $last_connection = null; |
||
0 ignored issues
–
show
|
|||
679 | public static $connections = array(); |
||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 5 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues.
Loading history...
|
|||
680 | |||
681 | 89 | public static function getConnection($link = null, $func = null) |
|
0 ignored issues
–
show
The return type could not be reliably inferred; please add a
@return annotation.
Our type inference engine in quite powerful, but sometimes the code does not
provide enough clues to go by. In these cases we request you to add a
Loading history...
|
|||
682 | { |
||
0 ignored issues
–
show
|
|||
683 | 89 | if ($link !== null) { |
|
0 ignored issues
–
show
|
|||
684 | 9 | return $link; |
|
0 ignored issues
–
show
|
|||
685 | } |
||
0 ignored issues
–
show
|
|||
686 | |||
687 | 89 | if (static::$last_connection === null) { |
|
0 ignored issues
–
show
|
|||
688 | 28 | $err = 'A link to the server could not be established'; |
|
0 ignored issues
–
show
|
|||
689 | 28 | if ($func !== null) { |
|
0 ignored issues
–
show
|
|||
690 | 28 | $err = $func . '(): no MySQL-Link resource supplied'; |
|
0 ignored issues
–
show
|
|||
691 | } |
||
0 ignored issues
–
show
|
|||
692 | 28 | trigger_error($err, E_USER_WARNING); |
|
0 ignored issues
–
show
|
|||
693 | 28 | return false; |
|
0 ignored issues
–
show
|
|||
694 | } |
||
0 ignored issues
–
show
|
|||
695 | |||
696 | 62 | return static::$last_connection; |
|
0 ignored issues
–
show
|
|||
697 | } |
||
0 ignored issues
–
show
|
|||
698 | |||
699 | 7 | public static function mysqlFieldInfo(\mysqli_result $result, $field, $what) |
|
0 ignored issues
–
show
The return type could not be reliably inferred; please add a
@return annotation.
Our type inference engine in quite powerful, but sometimes the code does not
provide enough clues to go by. In these cases we request you to add a
Loading history...
|
|||
700 | { |
||
0 ignored issues
–
show
|
|||
701 | try { |
||
0 ignored issues
–
show
|
|||
702 | 7 | $field = mysqli_fetch_field_direct($result, $field); |
|
0 ignored issues
–
show
|
|||
703 | 5 | } catch (\Exception $e) { |
|
0 ignored issues
–
show
|
|||
704 | 5 | trigger_error( |
|
0 ignored issues
–
show
|
|||
705 | 5 | sprintf( |
|
706 | 5 | 'mysql_field_%s(): Field %d is invalid for MySQL result index %s', |
|
707 | 5 | ($what !== 'length') ? $what : 'len', |
|
0 ignored issues
–
show
|
|||
708 | $field, |
||
709 | 5 | spl_object_hash($result) |
|
710 | ), |
||
711 | 5 | E_USER_WARNING |
|
712 | ); |
||
713 | // @codeCoverageIgnoreStart |
||
0 ignored issues
–
show
|
|||
714 | // PHPUnit turns the warning into an exception, so this never runs |
||
0 ignored issues
–
show
|
|||
715 | return false; |
||
0 ignored issues
–
show
|
|||
716 | // @codeCoverageIgnoreEnd |
||
0 ignored issues
–
show
|
|||
717 | } |
||
0 ignored issues
–
show
|
|||
718 | |||
719 | 2 | if ($what === 'type') { |
|
0 ignored issues
–
show
|
|||
720 | 2 | return static::getFieldType($field->type); |
|
0 ignored issues
–
show
|
|||
721 | } |
||
0 ignored issues
–
show
|
|||
722 | |||
723 | 2 | if ($what === 'flags') { |
|
0 ignored issues
–
show
|
|||
724 | 2 | return static::getFieldFlags($field->flags); |
|
0 ignored issues
–
show
|
|||
725 | } |
||
0 ignored issues
–
show
|
|||
726 | |||
727 | 2 | if (isset($field->{$what})) { |
|
0 ignored issues
–
show
|
|||
728 | 2 | return $field->{$what}; |
|
0 ignored issues
–
show
|
|||
729 | } |
||
0 ignored issues
–
show
|
|||
730 | |||
731 | return false; |
||
0 ignored issues
–
show
|
|||
732 | } |
||
0 ignored issues
–
show
|
|||
733 | |||
734 | 60 | public static function checkValidResult($result, $function) |
|
0 ignored issues
–
show
|
|||
735 | { |
||
0 ignored issues
–
show
|
|||
736 | 60 | if (!($result instanceof \mysqli_result)) { |
|
0 ignored issues
–
show
|
|||
737 | 22 | $type = strtolower(gettype($result)); |
|
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 11 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues.
Loading history...
|
|||
738 | 22 | $file = ""; |
|
0 ignored issues
–
show
The string literal
does not require double quotes, as per coding-style, please use single quotes.
PHP provides two ways to mark string literals. Either with single quotes String literals in single quotes on the other hand are evaluated very literally and the only two
characters that needs escaping in the literal are the single quote itself ( Double quoted string literals may contain other variables or more complex escape sequences. <?php
$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";
print $doubleQuoted;
will print an indented: If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear. For more information on PHP string literals and available escape sequences see the PHP core documentation.
Loading history...
Equals sign not aligned with surrounding assignments; expected 11 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues.
Loading history...
|
|||
739 | 22 | $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); |
|
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 6 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues.
Loading history...
|
|||
740 | 22 | $backtraceIndex = 0; |
|
0 ignored issues
–
show
|
|||
741 | |||
742 | /** |
||
0 ignored issues
–
show
|
|||
743 | * Iterate through backtrace until finding a backtrace with an origin |
||
0 ignored issues
–
show
|
|||
744 | * Some methods may not leave file and line metadata like call_user_func_array and __call |
||
0 ignored issues
–
show
|
|||
745 | */ |
||
746 | do { |
||
0 ignored issues
–
show
|
|||
747 | 22 | $currentBacktrace = $backtrace[$backtraceIndex]; |
|
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 5 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues.
Loading history...
|
|||
748 | 22 | $callerHasFileAndLine = isset($currentBacktrace['file'], $currentBacktrace['line']); |
|
0 ignored issues
–
show
|
|||
749 | |||
750 | 22 | if ($callerHasFileAndLine && $currentBacktrace['file'] != __FILE__) { |
|
0 ignored issues
–
show
|
|||
751 | 22 | $file = $currentBacktrace['file'] . ':' . $currentBacktrace['line']; |
|
0 ignored issues
–
show
|
|||
752 | } |
||
0 ignored issues
–
show
|
|||
753 | 22 | } while ($backtraceIndex++ < count($backtrace) && $file == ""); |
|
0 ignored issues
–
show
The string literal
does not require double quotes, as per coding-style, please use single quotes.
PHP provides two ways to mark string literals. Either with single quotes String literals in single quotes on the other hand are evaluated very literally and the only two
characters that needs escaping in the literal are the single quote itself ( Double quoted string literals may contain other variables or more complex escape sequences. <?php
$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";
print $doubleQuoted;
will print an indented: If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear. For more information on PHP string literals and available escape sequences see the PHP core documentation.
Loading history...
|
|||
754 | |||
755 | 22 | if ($function !== 'mysql_fetch_object') { |
|
0 ignored issues
–
show
|
|||
756 | 21 | trigger_error( |
|
0 ignored issues
–
show
|
|||
757 | 21 | "$function() expects parameter 1 to be resource, $type given on $file", |
|
0 ignored issues
–
show
As per coding-style, please use concatenation or
sprintf for the variable $function instead of interpolation.
It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings. // Instead of
$x = "foo $bar $baz";
// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
As per coding-style, please use concatenation or
sprintf for the variable $type instead of interpolation.
It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings. // Instead of
$x = "foo $bar $baz";
// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
As per coding-style, please use concatenation or
sprintf for the variable $file instead of interpolation.
It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings. // Instead of
$x = "foo $bar $baz";
// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
|
|||
758 | 21 | E_USER_WARNING |
|
759 | ); |
||
760 | } |
||
0 ignored issues
–
show
|
|||
761 | |||
762 | 1 | if ($function === 'mysql_fetch_object') { |
|
0 ignored issues
–
show
|
|||
763 | 1 | trigger_error( |
|
0 ignored issues
–
show
|
|||
764 | 1 | "$function(): supplied argument is not a valid MySQL result resource on $file", |
|
0 ignored issues
–
show
As per coding-style, please use concatenation or
sprintf for the variable $function instead of interpolation.
It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings. // Instead of
$x = "foo $bar $baz";
// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
As per coding-style, please use concatenation or
sprintf for the variable $file instead of interpolation.
It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings. // Instead of
$x = "foo $bar $baz";
// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
|
|||
765 | 1 | E_USER_WARNING |
|
766 | ); |
||
767 | } |
||
0 ignored issues
–
show
|
|||
768 | return false; |
||
0 ignored issues
–
show
|
|||
769 | } |
||
0 ignored issues
–
show
|
|||
770 | |||
771 | 38 | return true; |
|
0 ignored issues
–
show
|
|||
772 | } |
||
0 ignored issues
–
show
|
|||
773 | |||
774 | 1 | public static function escapeString($unescapedString) |
|
0 ignored issues
–
show
|
|||
775 | { |
||
0 ignored issues
–
show
|
|||
776 | 1 | $escapedString = ''; |
|
0 ignored issues
–
show
|
|||
777 | 1 | for ($i = 0, $max = strlen($unescapedString); $i < $max; $i++) { |
|
0 ignored issues
–
show
|
|||
778 | 1 | $escapedString .= self::escapeChar($unescapedString[$i]); |
|
0 ignored issues
–
show
|
|||
779 | } |
||
0 ignored issues
–
show
|
|||
780 | |||
781 | 1 | return $escapedString; |
|
0 ignored issues
–
show
|
|||
782 | } |
||
0 ignored issues
–
show
|
|||
783 | |||
784 | 2 | protected static function getFieldFlags($what) |
|
0 ignored issues
–
show
|
|||
785 | { |
||
0 ignored issues
–
show
|
|||
786 | // Order of flags taken from http://lxr.php.net/xref/PHP_5_6/ext/mysql/php_mysql.c#2507 |
||
0 ignored issues
–
show
|
|||
787 | $flags = array( |
||
0 ignored issues
–
show
|
|||
788 | 2 | MYSQLI_NOT_NULL_FLAG => 'not_null', |
|
0 ignored issues
–
show
|
|||
789 | 2 | MYSQLI_PRI_KEY_FLAG => 'primary_key', |
|
0 ignored issues
–
show
|
|||
790 | 2 | MYSQLI_UNIQUE_KEY_FLAG => 'unique_key', |
|
0 ignored issues
–
show
|
|||
791 | 2 | MYSQLI_MULTIPLE_KEY_FLAG => 'multiple_key', |
|
0 ignored issues
–
show
|
|||
792 | 2 | MYSQLI_BLOB_FLAG => 'blob', |
|
0 ignored issues
–
show
|
|||
793 | 2 | MYSQLI_UNSIGNED_FLAG => 'unsigned', |
|
0 ignored issues
–
show
|
|||
794 | 2 | MYSQLI_ZEROFILL_FLAG => 'zerofill', |
|
0 ignored issues
–
show
|
|||
795 | 2 | MYSQLI_BINARY_FLAG => 'binary', |
|
0 ignored issues
–
show
|
|||
796 | 2 | MYSQLI_ENUM_FLAG => 'enum', |
|
0 ignored issues
–
show
|
|||
797 | 2 | MYSQLI_SET_FLAG => 'set', |
|
0 ignored issues
–
show
|
|||
798 | 2 | MYSQLI_AUTO_INCREMENT_FLAG => 'auto_increment', |
|
0 ignored issues
–
show
|
|||
799 | 2 | MYSQLI_TIMESTAMP_FLAG => 'timestamp', |
|
0 ignored issues
–
show
|
|||
800 | ); |
||
801 | |||
802 | 2 | $fieldFlags = array(); |
|
0 ignored issues
–
show
|
|||
803 | 2 | foreach ($flags as $flag => $value) { |
|
0 ignored issues
–
show
|
|||
804 | 2 | if ($what & $flag) { |
|
0 ignored issues
–
show
|
|||
805 | 2 | $fieldFlags[] = $value; |
|
0 ignored issues
–
show
|
|||
806 | } |
||
0 ignored issues
–
show
|
|||
807 | } |
||
0 ignored issues
–
show
|
|||
808 | |||
809 | 2 | return implode(' ', $fieldFlags); |
|
0 ignored issues
–
show
|
|||
810 | } |
||
0 ignored issues
–
show
|
|||
811 | |||
812 | 2 | protected static function getFieldType($what) |
|
0 ignored issues
–
show
|
|||
813 | { |
||
0 ignored issues
–
show
|
|||
814 | $types = array( |
||
0 ignored issues
–
show
|
|||
815 | 2 | MYSQLI_TYPE_STRING => 'string', |
|
0 ignored issues
–
show
|
|||
816 | 2 | MYSQLI_TYPE_VAR_STRING => 'string', |
|
0 ignored issues
–
show
|
|||
817 | 2 | MYSQLI_TYPE_ENUM => 'string', |
|
0 ignored issues
–
show
|
|||
818 | 2 | MYSQLI_TYPE_SET => 'string', |
|
0 ignored issues
–
show
|
|||
819 | |||
820 | 2 | MYSQLI_TYPE_LONG => 'int', |
|
0 ignored issues
–
show
|
|||
821 | 2 | MYSQLI_TYPE_TINY => 'int', |
|
0 ignored issues
–
show
|
|||
822 | 2 | MYSQLI_TYPE_SHORT => 'int', |
|
0 ignored issues
–
show
|
|||
823 | 2 | MYSQLI_TYPE_INT24 => 'int', |
|
0 ignored issues
–
show
|
|||
824 | 2 | MYSQLI_TYPE_CHAR => 'int', |
|
0 ignored issues
–
show
|
|||
825 | 2 | MYSQLI_TYPE_LONGLONG => 'int', |
|
0 ignored issues
–
show
|
|||
826 | |||
827 | 2 | MYSQLI_TYPE_DECIMAL => 'real', |
|
0 ignored issues
–
show
|
|||
828 | 2 | MYSQLI_TYPE_FLOAT => 'real', |
|
0 ignored issues
–
show
|
|||
829 | 2 | MYSQLI_TYPE_DOUBLE => 'real', |
|
0 ignored issues
–
show
|
|||
830 | 2 | MYSQLI_TYPE_NEWDECIMAL => 'real', |
|
0 ignored issues
–
show
|
|||
831 | |||
832 | 2 | MYSQLI_TYPE_TINY_BLOB => 'blob', |
|
0 ignored issues
–
show
|
|||
833 | 2 | MYSQLI_TYPE_MEDIUM_BLOB => 'blob', |
|
0 ignored issues
–
show
|
|||
834 | 2 | MYSQLI_TYPE_LONG_BLOB => 'blob', |
|
0 ignored issues
–
show
|
|||
835 | 2 | MYSQLI_TYPE_BLOB => 'blob', |
|
0 ignored issues
–
show
|
|||
836 | |||
837 | 2 | MYSQLI_TYPE_NEWDATE => 'date', |
|
0 ignored issues
–
show
|
|||
838 | 2 | MYSQLI_TYPE_DATE => 'date', |
|
0 ignored issues
–
show
|
|||
839 | 2 | MYSQLI_TYPE_TIME => 'time', |
|
0 ignored issues
–
show
|
|||
840 | 2 | MYSQLI_TYPE_YEAR => 'year', |
|
0 ignored issues
–
show
|
|||
841 | 2 | MYSQLI_TYPE_DATETIME => 'datetime', |
|
0 ignored issues
–
show
|
|||
842 | 2 | MYSQLI_TYPE_TIMESTAMP => 'timestamp', |
|
0 ignored issues
–
show
|
|||
843 | |||
844 | 2 | MYSQLI_TYPE_NULL => 'null', |
|
0 ignored issues
–
show
|
|||
845 | |||
846 | 2 | MYSQLI_TYPE_GEOMETRY => 'geometry', |
|
0 ignored issues
–
show
|
|||
847 | ); |
||
848 | |||
849 | 2 | return isset($types[$what]) ? $types[$what] : 'unknown'; |
|
0 ignored issues
–
show
|
|||
850 | } |
||
0 ignored issues
–
show
|
|||
851 | |||
852 | 1 | protected static function escapeChar($char) |
|
0 ignored issues
–
show
The return type could not be reliably inferred; please add a
@return annotation.
Our type inference engine in quite powerful, but sometimes the code does not
provide enough clues to go by. In these cases we request you to add a
Loading history...
|
|||
853 | { |
||
0 ignored issues
–
show
|
|||
854 | 1 | switch ($char) { |
|
0 ignored issues
–
show
|
|||
855 | 1 | case "\0": |
|
0 ignored issues
–
show
|
|||
856 | 1 | $esc = "\\0"; |
|
0 ignored issues
–
show
|
|||
857 | 1 | break; |
|
0 ignored issues
–
show
|
|||
858 | 1 | case "\n": |
|
0 ignored issues
–
show
|
|||
859 | 1 | $esc = "\\n"; |
|
0 ignored issues
–
show
|
|||
860 | 1 | break; |
|
0 ignored issues
–
show
|
|||
861 | 1 | case "\r": |
|
0 ignored issues
–
show
|
|||
862 | 1 | $esc = "\\r"; |
|
0 ignored issues
–
show
|
|||
863 | 1 | break; |
|
0 ignored issues
–
show
|
|||
864 | 1 | case '\\': |
|
0 ignored issues
–
show
|
|||
865 | 1 | case '\'': |
|
0 ignored issues
–
show
|
|||
866 | 1 | case '"': |
|
0 ignored issues
–
show
|
|||
867 | 1 | $esc = "\\{$char}"; |
|
0 ignored issues
–
show
As per coding-style, please use concatenation or
sprintf for the variable $char instead of interpolation.
It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings. // Instead of
$x = "foo $bar $baz";
// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
|
|||
868 | 1 | break; |
|
0 ignored issues
–
show
|
|||
869 | 1 | case "\032": |
|
0 ignored issues
–
show
|
|||
870 | 1 | $esc = "\\Z"; |
|
0 ignored issues
–
show
The string literal
\\Z does not require double quotes, as per coding-style, please use single quotes.
PHP provides two ways to mark string literals. Either with single quotes String literals in single quotes on the other hand are evaluated very literally and the only two
characters that needs escaping in the literal are the single quote itself ( Double quoted string literals may contain other variables or more complex escape sequences. <?php
$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";
print $doubleQuoted;
will print an indented: If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear. For more information on PHP string literals and available escape sequences see the PHP core documentation.
Loading history...
|
|||
871 | 1 | break; |
|
0 ignored issues
–
show
|
|||
872 | default: |
||
0 ignored issues
–
show
|
|||
873 | 1 | $esc = $char; |
|
0 ignored issues
–
show
|
|||
874 | 1 | break; |
|
0 ignored issues
–
show
|
|||
875 | } |
||
0 ignored issues
–
show
|
|||
876 | |||
877 | 1 | return $esc; |
|
0 ignored issues
–
show
|
|||
878 | } |
||
0 ignored issues
–
show
|
|||
879 | } |
||
0 ignored issues
–
show
|
|||
880 | } |
||
0 ignored issues
–
show
|
|||
881 |