| Conditions | 14 |
| Paths | 24 |
| Total Lines | 45 |
| Code Lines | 33 |
| 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 | $lob = null; |
||
| 24 | $ldt = null; |
||
| 25 | foreach ($data as $i => $v) { |
||
| 26 | switch (gettype($v)) { |
||
| 27 | case 'boolean': |
||
| 28 | case 'integer': |
||
| 29 | $data[$i] = (int) $v; |
||
| 30 | \oci_bind_by_name($this->statement, 'f'.$i, $data[$i], -1, \SQLT_INT); |
||
| 31 | break; |
||
| 32 | default: |
||
| 33 | // keep in mind oracle needs a transaction when inserting LOBs, aside from the specific syntax: |
||
| 34 | // INSERT INTO table (column, lobcolumn) VALUES (?, ?, EMPTY_BLOB()) RETURNING lobcolumn INTO ? |
||
| 35 | if (is_resource($v) && get_resource_type($v) === 'stream') { |
||
| 36 | $ldt = $v; |
||
| 37 | $lob = $this->driver->lob(); |
||
| 38 | \oci_bind_by_name($this->statement, 'f'.$i, $lob, -1, \OCI_B_BLOB); |
||
| 39 | continue; |
||
| 40 | } |
||
| 41 | if (!is_string($data[$i]) && !is_null($data[$i])) { |
||
| 42 | $data[$i] = serialize($data[$i]); |
||
| 43 | } |
||
| 44 | \oci_bind_by_name($this->statement, 'f'.$i, $data[$i]); |
||
| 45 | break; |
||
| 46 | } |
||
| 47 | } |
||
| 48 | $temp = \oci_execute($this->statement, $this->driver->isTransaction() ? \OCI_NO_AUTO_COMMIT : \OCI_COMMIT_ON_SUCCESS); |
||
| 49 | if (!$temp) { |
||
| 50 | $err = \oci_error($this->statement); |
||
| 51 | if (!$err) { |
||
|
|
|||
| 52 | $err = []; |
||
| 53 | } |
||
| 54 | throw new DBException('Could not execute query : '.implode(',', $err)); |
||
| 55 | } |
||
| 56 | if ($lob) { |
||
| 57 | while (!feof($ldt) && ($ltmp = fread($ldt, 8192)) !== false) { |
||
| 58 | $lob->write($ltmp); |
||
| 59 | $lob->flush(); |
||
| 60 | } |
||
| 61 | $lob->free(); |
||
| 62 | } |
||
| 63 | return new Result($this->statement); |
||
| 64 | } |
||
| 65 | } |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.