| Conditions | 4 |
| Paths | 4 |
| Total Lines | 25 |
| Code Lines | 12 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 12 |
| CRAP Score | 4 |
| Changes | 0 | ||
| 1 | <?php |
||
| 32 | 6 | public function queryWithParam(string $query, array $param) : PDOStatement |
|
| 33 | { |
||
| 34 | 6 | $statment = $this->prepare($query); |
|
| 35 | |||
| 36 | 6 | foreach ($param as $value) { |
|
| 37 | 5 | if (count($value) < 2) { |
|
| 38 | 1 | throw new InvalidArgumentException(__METHOD__.': Parameters array must contain at least two elements with this form: [\':name\', \'value\']'); |
|
| 39 | } |
||
| 40 | |||
| 41 | 4 | if (strpos($value[0], ':') !== 0) { |
|
| 42 | 1 | throw new InvalidArgumentException(__METHOD__.': Parameter name will be in the form :name'); |
|
| 43 | } |
||
| 44 | |||
| 45 | //reassign as reference |
||
| 46 | //because bindParam need it as reference |
||
| 47 | 3 | $ref = $value; |
|
| 48 | 3 | $ref[1] = &$value[1]; |
|
| 49 | |||
| 50 | 3 | call_user_func_array([$statment, "bindParam"], $ref); |
|
| 51 | } |
||
| 52 | |||
| 53 | 4 | $statment->execute(); |
|
| 54 | |||
| 55 | 3 | return $statment; |
|
| 56 | } |
||
| 57 | } |
||
| 58 |