| Total Complexity | 8 |
| Total Lines | 71 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 9 | class MySQLLogicBindings implements LogicBindingInterface |
||
| 10 | { |
||
| 11 | /** |
||
| 12 | * Bind a boolean value as bool or null. |
||
| 13 | * |
||
| 14 | * @param int|bool|null $value |
||
| 15 | * |
||
| 16 | * @return array |
||
| 17 | * @throws TypeError |
||
| 18 | */ |
||
| 19 | public function bBoolNullable($value = null): array |
||
| 20 | { |
||
| 21 | // use NULL |
||
| 22 | if ($value === null) { |
||
| 23 | return [null, PDO::PARAM_NULL]; |
||
| 24 | } |
||
| 25 | |||
| 26 | return $this->bBool($value); |
||
| 27 | } |
||
| 28 | |||
| 29 | /** |
||
| 30 | * Bind a boolean value as bool. |
||
| 31 | * |
||
| 32 | * @param int|bool|null $value |
||
| 33 | * |
||
| 34 | * @return array |
||
| 35 | * @throws TypeError |
||
| 36 | */ |
||
| 37 | public function bBool(?$value): array |
||
|
|
|||
| 38 | { |
||
| 39 | if ($value === null) { |
||
| 40 | throw new TypeError('Can not bind ' . gettype($value) . ':(' . $value . ') in boolean spot.'); |
||
| 41 | } |
||
| 42 | |||
| 43 | return [$value, PDO::PARAM_BOOL]; |
||
| 44 | } |
||
| 45 | |||
| 46 | |||
| 47 | /** |
||
| 48 | * Bind a boolean value as int or null. |
||
| 49 | * |
||
| 50 | * @param int|bool|null $value |
||
| 51 | * |
||
| 52 | * @return array |
||
| 53 | * @throws TypeError |
||
| 54 | */ |
||
| 55 | public function bBoolIntNullable($value = null): array |
||
| 56 | { |
||
| 57 | // use NULL |
||
| 58 | if ($value === null) { |
||
| 59 | return [null, PDO::PARAM_NULL]; |
||
| 60 | } |
||
| 61 | |||
| 62 | return $this->bBoolInt($value); |
||
| 63 | } |
||
| 64 | |||
| 65 | /** |
||
| 66 | * Bind a boolean value as int. |
||
| 67 | * |
||
| 68 | * @param int|bool|null $value |
||
| 69 | * |
||
| 70 | * @return array |
||
| 71 | * @throws TypeError |
||
| 72 | */ |
||
| 73 | public function bBoolInt(?$value): array |
||
| 74 | { |
||
| 75 | if ($value === null) { |
||
| 76 | throw new TypeError('Can not bind ' . gettype($value) . ':(' . $value . ') in boolean / integer spot.'); |
||
| 77 | } |
||
| 78 | |||
| 79 | return [(int) $value, PDO::PARAM_INT]; |
||
| 80 | } |
||
| 82 |