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 |
||
| 34 | class OCIExpressionBuilder extends ExpressionBuilder { |
||
| 35 | |||
| 36 | /** |
||
| 37 | * @param mixed $column |
||
| 38 | * @param mixed|null $type |
||
| 39 | * @return array|IQueryFunction|string |
||
| 40 | */ |
||
| 41 | protected function prepareColumn($column, $type) { |
||
| 49 | |||
| 50 | /** |
||
| 51 | * @inheritdoc |
||
| 52 | */ |
||
| 53 | public function comparison($x, $operator, $y, $type = null) { |
||
| 59 | |||
| 60 | /** |
||
| 61 | * @inheritdoc |
||
| 62 | */ |
||
| 63 | public function eq($x, $y, $type = null) { |
||
| 69 | |||
| 70 | /** |
||
| 71 | * @inheritdoc |
||
| 72 | */ |
||
| 73 | public function neq($x, $y, $type = null) { |
||
| 79 | |||
| 80 | /** |
||
| 81 | * @inheritdoc |
||
| 82 | */ |
||
| 83 | public function lt($x, $y, $type = null) { |
||
| 89 | |||
| 90 | /** |
||
| 91 | * @inheritdoc |
||
| 92 | */ |
||
| 93 | public function lte($x, $y, $type = null) { |
||
| 99 | |||
| 100 | /** |
||
| 101 | * @inheritdoc |
||
| 102 | */ |
||
| 103 | public function gt($x, $y, $type = null) { |
||
| 109 | |||
| 110 | /** |
||
| 111 | * @inheritdoc |
||
| 112 | */ |
||
| 113 | public function gte($x, $y, $type = null) { |
||
| 119 | |||
| 120 | /** |
||
| 121 | * @inheritdoc |
||
| 122 | */ |
||
| 123 | public function in($x, $y, $type = null) { |
||
| 129 | |||
| 130 | /** |
||
| 131 | * @inheritdoc |
||
| 132 | */ |
||
| 133 | public function notIn($x, $y, $type = null) { |
||
| 139 | |||
| 140 | /** |
||
| 141 | * Returns a IQueryFunction that casts the column to the given type |
||
| 142 | * |
||
| 143 | * @param string $column |
||
| 144 | * @param mixed $type One of IQueryBuilder::PARAM_* |
||
| 145 | * @return IQueryFunction |
||
| 146 | */ |
||
| 147 | View Code Duplication | public function castColumn($column, $type) { |
|
| 155 | |||
| 156 | /** |
||
| 157 | * @inheritdoc |
||
| 158 | */ |
||
| 159 | public function like($x, $y, $type = null) { |
||
| 162 | |||
| 163 | /** |
||
| 164 | * @inheritdoc |
||
| 165 | */ |
||
| 166 | public function iLike($x, $y, $type = null) { |
||
| 171 | } |
||
| 172 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.