Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
| 1 | <?php |
||
| 9 | class OracleProcessor extends Processor |
||
| 10 | { |
||
| 11 | /** |
||
| 12 | * Process an "insert get ID" query. |
||
| 13 | * |
||
| 14 | * @param Builder $query |
||
| 15 | * @param string $sql |
||
| 16 | * @param array $values |
||
| 17 | * @param string $sequence |
||
| 18 | * @return int |
||
| 19 | */ |
||
| 20 | public function processInsertGetId(Builder $query, $sql, $values, $sequence = null) |
||
| 36 | |||
| 37 | /** |
||
| 38 | * Get prepared statement. |
||
| 39 | * |
||
| 40 | * @param Builder $query |
||
| 41 | * @param string $sql |
||
| 42 | * @return \PDOStatement | \Yajra\Pdo\Oci8 |
||
| 43 | */ |
||
| 44 | private function prepareStatement(Builder $query, $sql) |
||
| 50 | |||
| 51 | /** |
||
| 52 | * save Query with Blob returning primary key value |
||
| 53 | * |
||
| 54 | * @param Builder $query |
||
| 55 | * @param string $sql |
||
| 56 | * @param array $values |
||
| 57 | * @param array $binaries |
||
| 58 | * @return int |
||
| 59 | */ |
||
| 60 | public function saveLob(Builder $query, $sql, array $values, array $binaries) |
||
| 89 | } |
||
| 90 |
If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration: