| Conditions | 14 |
| Paths | 5 |
| Total Lines | 44 |
| Code Lines | 36 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 20 | public function execute(array $data = []) : ResultInterface |
||
| 21 | { |
||
| 22 | $data = array_values($data); |
||
| 23 | if ($this->statement->paramCount()) { |
||
| 24 | if (count($data) < $this->statement->paramCount()) { |
||
| 25 | throw new DBException('Prepared execute - not enough parameters.'); |
||
| 26 | } |
||
| 27 | foreach ($data as $i => $v) { |
||
| 28 | switch (gettype($v)) { |
||
| 29 | case 'boolean': |
||
| 30 | case 'integer': |
||
| 31 | $this->statement->bindValue(':i'.$i, (int) $v, \SQLITE3_INTEGER); |
||
| 32 | break; |
||
| 33 | case 'double': |
||
| 34 | $this->statement->bindValue(':i'.$i, $v, \SQLITE3_FLOAT); |
||
| 35 | break; |
||
| 36 | case 'array': |
||
| 37 | $this->statement->bindValue(':i'.$i, implode(',', $v), \SQLITE3_TEXT); |
||
| 38 | break; |
||
| 39 | case 'object': |
||
| 40 | $this->statement->bindValue(':i'.$i, serialize($v), \SQLITE3_TEXT); |
||
| 41 | break; |
||
| 42 | case 'resource': |
||
| 43 | if (is_resource($v) && get_resource_type($v) === 'stream') { |
||
| 44 | $this->statement->bindValue(':i'.$i, stream_get_contents($v), \SQLITE3_TEXT); |
||
| 45 | } else { |
||
| 46 | $this->statement->bindValue(':i'.$i, serialize($v), \SQLITE3_TEXT); |
||
| 47 | } |
||
| 48 | break; |
||
| 49 | case 'NULL': |
||
| 50 | $this->statement->bindValue(':i'.$i, null, \SQLITE3_NULL); |
||
| 51 | break; |
||
| 52 | default: |
||
| 53 | $this->statement->bindValue(':i'.$i, (string) $v, \SQLITE3_TEXT); |
||
| 54 | break; |
||
| 55 | } |
||
| 56 | } |
||
| 57 | } |
||
| 58 | $rtrn = $this->statement->execute(); |
||
| 59 | if (!$rtrn) { |
||
| 60 | throw new DBException('Prepared execute error : '.$this->driver->lastErrorMsg()); |
||
| 61 | } |
||
| 62 | return new Result($rtrn, $this->driver->lastInsertRowID(), $this->driver->changes()); |
||
| 63 | } |
||
| 64 | } |