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 |
||
| 7 | class Sequence |
||
| 8 | { |
||
| 9 | /** |
||
| 10 | * @var \Illuminate\Database\Connection|\Yajra\Oci8\Oci8Connection |
||
| 11 | */ |
||
| 12 | protected $connection; |
||
| 13 | |||
| 14 | /** |
||
| 15 | * @param Connection $connection |
||
| 16 | */ |
||
| 17 | 3 | public function __construct(Connection $connection) |
|
| 21 | |||
| 22 | /** |
||
| 23 | * function to create oracle sequence. |
||
| 24 | * |
||
| 25 | * @param string $name |
||
| 26 | * @param int $start |
||
| 27 | * @param bool $nocache |
||
| 28 | * @param int $min |
||
| 29 | * @param bool $max |
||
| 30 | 3 | * @param int $increment |
|
| 31 | * @return bool |
||
| 32 | 3 | */ |
|
| 33 | public function create($name, $start = 1, $nocache = false, $min = 1, $max = false, $increment = 1) |
||
| 49 | |||
| 50 | /** |
||
| 51 | * Wrap sequence name with schema prefix. |
||
| 52 | * |
||
| 53 | * @param string $name |
||
| 54 | * @return string |
||
| 55 | */ |
||
| 56 | public function wrap($name) |
||
| 64 | |||
| 65 | /** |
||
| 66 | * function to safely drop sequence db object. |
||
| 67 | * |
||
| 68 | * @param string $name |
||
| 69 | * @return bool |
||
| 70 | */ |
||
| 71 | public function drop($name) |
||
| 91 | |||
| 92 | /** |
||
| 93 | * function to check if sequence exists. |
||
| 94 | * |
||
| 95 | * @param string $name |
||
| 96 | * @return bool |
||
| 97 | */ |
||
| 98 | View Code Duplication | public function exists($name) |
|
| 110 | |||
| 111 | /** |
||
| 112 | * get sequence next value. |
||
| 113 | * |
||
| 114 | * @param string $name |
||
| 115 | * @return int |
||
| 116 | */ |
||
| 117 | View Code Duplication | public function nextValue($name) |
|
| 127 | |||
| 128 | /** |
||
| 129 | * same function as lastInsertId. added for clarity with oracle sql statement. |
||
| 130 | * |
||
| 131 | * @param string $name |
||
| 132 | * @return int |
||
| 133 | */ |
||
| 134 | public function currentValue($name) |
||
| 138 | |||
| 139 | /** |
||
| 140 | * function to get oracle sequence last inserted id. |
||
| 141 | * |
||
| 142 | * @param string $name |
||
| 143 | * @return int |
||
| 144 | */ |
||
| 145 | View Code Duplication | public function lastInsertId($name) |
|
| 156 | } |
||
| 157 |