1 | <?php |
||
11 | class Database |
||
12 | { |
||
13 | /** |
||
14 | * @var array $options used when creating the PDO object |
||
15 | * @var PDO $pdo the PDO object |
||
16 | * @var PDOStatement $stmt the latest PDOStatement used |
||
17 | */ |
||
18 | protected $options; |
||
19 | private $pdo = null; |
||
20 | private $stmt = null; |
||
21 | |||
22 | |||
23 | |||
24 | /** |
||
25 | * Constructor creating a PDO object connecting to a choosen database. |
||
26 | * |
||
27 | * @param array $options containing details for connecting to the database. |
||
28 | */ |
||
29 | 8 | public function __construct($options = []) |
|
33 | |||
34 | |||
35 | |||
36 | /** |
||
37 | * Set options and connection details. |
||
38 | * |
||
39 | * @param array $options containing details for connecting to the database. |
||
40 | * |
||
41 | * @return void |
||
42 | */ |
||
43 | 9 | public function setOptions($options = []) |
|
58 | |||
59 | |||
60 | |||
61 | /** |
||
62 | * Set a single option. |
||
63 | * |
||
64 | * @param string $option which to set. |
||
65 | * @param mixed $value to set. |
||
66 | * |
||
67 | * @return self |
||
68 | */ |
||
69 | public function setOption($option, $value) |
||
74 | |||
75 | |||
76 | |||
77 | /** |
||
78 | * Connect to the database, allow being called multiple times |
||
79 | * but ignore when connection is already made. |
||
80 | * |
||
81 | * @return self |
||
82 | * |
||
83 | * @throws \Anax\Database\Exception |
||
84 | */ |
||
85 | 11 | public function connect() |
|
114 | |||
115 | |||
116 | |||
117 | /** |
||
118 | * Support arrays in params, extract array items and add to $params |
||
119 | * and insert ? for each entry in the array. |
||
120 | * |
||
121 | * @param string $query as the query to prepare. |
||
122 | * @param array $params the parameters that may contain arrays. |
||
123 | * |
||
124 | * @return array with query and params. |
||
125 | */ |
||
126 | 9 | private function expandParamArray($query, $params) |
|
153 | |||
154 | |||
155 | |||
156 | /** |
||
157 | * Execute a select-query with arguments and return the resultset. |
||
158 | * |
||
159 | * @param string $query the SQL statement |
||
160 | * @param array $params the params array |
||
161 | * |
||
162 | * @return array with resultset |
||
163 | */ |
||
164 | public function executeFetchAll($query, $params = []) |
||
169 | |||
170 | |||
171 | |||
172 | /** |
||
173 | * Execute a select-query with arguments and return the first row |
||
174 | * in the resultset. |
||
175 | * |
||
176 | * @param string $query the SQL statement |
||
177 | * @param array $params the params array |
||
178 | * |
||
179 | * @return array with resultset |
||
180 | */ |
||
181 | 1 | public function executeFetch($query, $params = []) |
|
186 | |||
187 | |||
188 | |||
189 | /** |
||
190 | * Execute a select-query with arguments and insert the results into |
||
191 | * a new object of the class. |
||
192 | * |
||
193 | * @param string $query the SQL statement |
||
194 | * @param array $params the params array |
||
195 | * @param string $class the class to create an object of and insert into |
||
196 | * |
||
197 | * @return array with resultset |
||
198 | */ |
||
199 | public function executeFetchClass($query, $params, $class) |
||
205 | |||
206 | |||
207 | |||
208 | /** |
||
209 | * Execute a select-query with arguments and insert the results into |
||
210 | * an existing object. |
||
211 | * |
||
212 | * @param string $query the SQL statement |
||
213 | * @param array $params the params array |
||
|
|||
214 | * @param string $object the existing object to insert into |
||
215 | * |
||
216 | * @return array with resultset |
||
217 | */ |
||
218 | public function executeFetchInto($query, $param, $object = null) |
||
228 | |||
229 | |||
230 | |||
231 | /** |
||
232 | * Fetch all resultset. |
||
233 | * |
||
234 | * @return array with resultset. |
||
235 | */ |
||
236 | public function fetchAll() |
||
240 | |||
241 | |||
242 | |||
243 | /** |
||
244 | * Fetch one resultset. |
||
245 | * |
||
246 | * @return array with resultset. |
||
247 | */ |
||
248 | public function fetch() |
||
252 | |||
253 | |||
254 | |||
255 | /** |
||
256 | * Fetch one resultset as a new object from this class. |
||
257 | * |
||
258 | * @param object $class which type of object to instantiate. |
||
259 | * |
||
260 | * @return array with resultset. |
||
261 | */ |
||
262 | public function fetchClass($class) |
||
267 | |||
268 | |||
269 | |||
270 | /** |
||
271 | * Fetch full resultset as new objects from this class. |
||
272 | * |
||
273 | * @param object $class which type of object to instantiate. |
||
274 | * |
||
275 | * @return array with resultset. |
||
276 | */ |
||
277 | 2 | public function fetchAllClass($class) |
|
282 | |||
283 | |||
284 | |||
285 | /** |
||
286 | * Fetch one resultset into an object. |
||
287 | * |
||
288 | * @param object $object to insert values into. |
||
289 | * |
||
290 | * @return array with resultset. |
||
291 | */ |
||
292 | 1 | public function fetchInto($object) |
|
297 | |||
298 | |||
299 | |||
300 | /** |
||
301 | * Execute a SQL-query and ignore the resultset. |
||
302 | * |
||
303 | * @param string $query the SQL statement |
||
304 | * @param array $params the params array |
||
305 | * |
||
306 | * @return self |
||
307 | * |
||
308 | * @throws Exception when failing to prepare question. |
||
309 | */ |
||
310 | 9 | public function execute($query, $params = []) |
|
331 | |||
332 | |||
333 | |||
334 | /** |
||
335 | * Throw exception using detailed message. |
||
336 | * |
||
337 | * @param string $msg detailed error message from PDO |
||
338 | * @param string $query query to execute |
||
339 | * @param array $param to match ? in statement |
||
340 | * |
||
341 | * @return void |
||
342 | * |
||
343 | * @throws \Anax\Database\Exception |
||
344 | */ |
||
345 | protected function createException($msg, $query, $param) |
||
361 | |||
362 | |||
363 | |||
364 | /** |
||
365 | * Throw exception when pdo failed using detailed message. |
||
366 | * |
||
367 | * @param string $query query to execute |
||
368 | * @param array $param to match ? in statement |
||
369 | * |
||
370 | * @return void |
||
371 | * |
||
372 | * @throws \Anax\Database\Exception |
||
373 | */ |
||
374 | protected function pdoException($query, $param) |
||
378 | |||
379 | |||
380 | |||
381 | /** |
||
382 | * Throw exception when statement failed using detailed message. |
||
383 | * |
||
384 | * @param string $query query to execute |
||
385 | * @param array $param to match ? in statement |
||
386 | * |
||
387 | * @return void |
||
388 | * |
||
389 | * @throws \Anax\Database\Exception |
||
390 | */ |
||
391 | protected function statementException($query, $param) |
||
395 | |||
396 | |||
397 | |||
398 | /** |
||
399 | * Return last insert id from autoincremented key on INSERT. |
||
400 | * |
||
401 | * @return integer as last insert id. |
||
402 | */ |
||
403 | 4 | public function lastInsertId() |
|
407 | |||
408 | |||
409 | |||
410 | /** |
||
411 | * Return rows affected of last INSERT, UPDATE, DELETE |
||
412 | * |
||
413 | * @return integer as rows affected on last statement |
||
414 | */ |
||
415 | 1 | public function rowCount() |
|
419 | |||
420 | |||
421 | |||
422 | /** |
||
423 | * Fetch one resultset as an object from this class. |
||
424 | * OBSOLETE replaced by fetchClass |
||
425 | * |
||
426 | * @param object $class which type of object to instantiate. |
||
427 | * |
||
428 | * @return array with resultset. |
||
429 | */ |
||
430 | public function fetchObject($class) |
||
434 | |||
435 | |||
436 | |||
437 | /** |
||
438 | * Fetch one resultset. OBSOLETE replace by fetch() |
||
439 | * |
||
440 | * @return array with resultset. |
||
441 | */ |
||
442 | public function fetchOne() |
||
446 | } |
||
447 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.
Consider the following example. The parameter
$ireland
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was changed, but the annotation was not.