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 | * Creates a $x = '' statement, because Oracle needs a different check |
||
| 142 | * |
||
| 143 | * @param string $x The field in string format to be inspected by the comparison. |
||
| 144 | * @return string |
||
| 145 | * @since 13.0.0 |
||
| 146 | */ |
||
| 147 | public function emptyString($x) { |
||
| 148 | return $this->isNull($x); |
||
| 149 | } |
||
| 150 | |||
| 151 | /** |
||
| 152 | * Creates a `$x <> ''` statement, because Oracle needs a different check |
||
| 153 | * |
||
| 154 | * @param string $x The field in string format to be inspected by the comparison. |
||
| 155 | * @return string |
||
| 156 | * @since 13.0.0 |
||
| 157 | */ |
||
| 158 | public function nonEmptyString($x) { |
||
| 159 | return $this->isNotNull($x); |
||
| 160 | } |
||
| 161 | |||
| 162 | /** |
||
| 163 | * Returns a IQueryFunction that casts the column to the given type |
||
| 164 | * |
||
| 165 | * @param string $column |
||
| 166 | * @param mixed $type One of IQueryBuilder::PARAM_* |
||
| 167 | * @return IQueryFunction |
||
| 168 | */ |
||
| 169 | View Code Duplication | public function castColumn($column, $type) { |
|
| 177 | |||
| 178 | /** |
||
| 179 | * @inheritdoc |
||
| 180 | */ |
||
| 181 | public function like($x, $y, $type = null) { |
||
| 184 | |||
| 185 | /** |
||
| 186 | * @inheritdoc |
||
| 187 | */ |
||
| 188 | public function iLike($x, $y, $type = null) { |
||
| 193 | } |
||
| 194 |