| Conditions | 11 |
| Paths | 24 |
| Total Lines | 41 |
| Code Lines | 30 |
| 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 | //var_dump($data); |
||
| 24 | foreach ($data as $i => $v) { |
||
| 25 | switch (gettype($v)) { |
||
| 26 | case 'boolean': |
||
| 27 | $this->statement->bindValue($i+1, $v, \PDO::PARAM_BOOL); |
||
| 28 | break; |
||
| 29 | case 'integer': |
||
| 30 | $this->statement->bindValue($i+1, $v, \PDO::PARAM_INT); |
||
| 31 | break; |
||
| 32 | case 'NULL': |
||
| 33 | $this->statement->bindValue($i+1, $v, \PDO::PARAM_NULL); |
||
| 34 | break; |
||
| 35 | case 'double': |
||
| 36 | $this->statement->bindValue($i+1, $v); |
||
| 37 | break; |
||
| 38 | default: |
||
| 39 | // keep in mind oracle needs a transaction when inserting LOBs, aside from the specific syntax: |
||
| 40 | // INSERT INTO table (column, lobcolumn) VALUES (?, ?, EMPTY_BLOB()) RETURNING lobcolumn INTO ? |
||
| 41 | if (is_resource($v) && get_resource_type($v) === 'stream') { |
||
| 42 | $this->statement->bindParam($i+1, $v, \PDO::PARAM_LOB); |
||
| 43 | continue; |
||
| 44 | } |
||
| 45 | if (!is_string($data[$i])) { |
||
| 46 | $data[$i] = serialize($data[$i]); |
||
| 47 | } |
||
| 48 | $this->statement->bindValue($i+1, $v); |
||
| 49 | break; |
||
| 50 | } |
||
| 51 | } |
||
| 52 | try { |
||
| 53 | if (!$this->statement->execute()) { |
||
| 54 | throw new DBException('Prepared execute error'); |
||
| 55 | } |
||
| 56 | } catch (\Exception $e) { |
||
| 57 | throw new DBException($e->getMessage()); |
||
| 58 | } |
||
| 59 | return new Result($this->statement, $this->driver); |
||
| 60 | } |
||
| 61 | } |