| Total Complexity | 7 |
| Total Lines | 70 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 12 | class Statement extends PDOStatement |
||
| 13 | { |
||
| 14 | |||
| 15 | /** |
||
| 16 | * @var DB |
||
| 17 | */ |
||
| 18 | protected $db; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * PDO requires this to be protected. |
||
| 22 | * |
||
| 23 | * @param DB $db |
||
| 24 | */ |
||
| 25 | protected function __construct(DB $db) |
||
| 26 | { |
||
| 27 | $this->db = $db; |
||
| 28 | } |
||
| 29 | |||
| 30 | /** |
||
| 31 | * Fluent execution. |
||
| 32 | * |
||
| 33 | * @param array $args |
||
| 34 | * @return $this |
||
| 35 | */ |
||
| 36 | public function __invoke(array $args = null) |
||
| 37 | { |
||
| 38 | $this->execute($args); |
||
| 39 | return $this; |
||
| 40 | } |
||
| 41 | |||
| 42 | /** |
||
| 43 | * The query string. |
||
| 44 | * |
||
| 45 | * @return string |
||
| 46 | */ |
||
| 47 | public function __toString() |
||
| 50 | } |
||
| 51 | |||
| 52 | /** |
||
| 53 | * Logs. |
||
| 54 | * PHP returns `false` instead of throwing if too many arguments were given. |
||
| 55 | * This checks for that and throws. |
||
| 56 | * |
||
| 57 | * @param array $args |
||
| 58 | * @return bool |
||
| 59 | * @throws ArgumentCountError |
||
| 60 | */ |
||
| 61 | public function execute($args = null) |
||
| 62 | { |
||
| 63 | $this->db->log($this->queryString); |
||
| 64 | if ($result = !parent::execute($args)) { |
||
| 65 | $info = $this->errorInfo(); |
||
| 66 | if ($info[0] == 0) { |
||
| 67 | $argc = count($args); |
||
|
|
|||
| 68 | throw new ArgumentCountError("Too many arguments given ({$argc})"); |
||
| 69 | } |
||
| 70 | } |
||
| 71 | return $result; |
||
| 72 | } |
||
| 73 | |||
| 74 | /** |
||
| 75 | * `lastInsertId()` |
||
| 76 | * |
||
| 77 | * @return int |
||
| 78 | */ |
||
| 79 | public function getId(): int |
||
| 82 | } |
||
| 83 | } |
||
| 84 |