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 |
||
| 32 | trait JoinTrait |
||
| 33 | { |
||
| 34 | use AbstractTrait; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * {@inheritDoc} |
||
| 38 | */ |
||
| 39 | public function join($secondTable, $onClause = '') |
||
| 43 | |||
| 44 | /** |
||
| 45 | * {@inheritDoc} |
||
| 46 | */ |
||
| 47 | public function leftJoin($secondTable, $onClause = '') |
||
| 51 | |||
| 52 | /** |
||
| 53 | * {@inheritDoc} |
||
| 54 | */ |
||
| 55 | public function leftOuterJoin($secondTable, $onClause = '') |
||
| 59 | |||
| 60 | /** |
||
| 61 | * {@inheritDoc} |
||
| 62 | */ |
||
| 63 | public function rightJoin($secondTable, $onClause = '') |
||
| 67 | |||
| 68 | /** |
||
| 69 | * {@inheritDoc} |
||
| 70 | */ |
||
| 71 | public function rightOuterJoin($secondTable, $onClause = '') |
||
| 75 | |||
| 76 | /** |
||
| 77 | * {@inheritDoc} |
||
| 78 | */ |
||
| 79 | public function outerJoin($secondTable, $onClause = '') |
||
| 83 | |||
| 84 | /** |
||
| 85 | * {@inheritDoc} |
||
| 86 | */ |
||
| 87 | public function crossJoin($secondTable, $onClause = '') |
||
| 91 | |||
| 92 | /** |
||
| 93 | * {@inheritDoc} |
||
| 94 | */ |
||
| 95 | public function joinRaw( |
||
| 104 | |||
| 105 | /** |
||
| 106 | * The real join |
||
| 107 | * |
||
| 108 | * @param string $joinType |
||
| 109 | * @param string|string[]|SelectStatementInterface $secondTable |
||
| 110 | * @param string|string[]|ExpressionInterface $onClause |
||
| 111 | * @param bool $rawMode |
||
| 112 | * @return $this |
||
| 113 | * @access protected |
||
| 114 | */ |
||
| 115 | protected function realJoin( |
||
| 133 | |||
| 134 | /** |
||
| 135 | * Fix join table |
||
| 136 | * |
||
| 137 | * @param string|string[]|SelectStatementInterface $table |
||
| 138 | * @return array [table, alias] |
||
| 139 | * @access protected |
||
| 140 | */ |
||
| 141 | protected function fixJoinTable($table) |
||
| 151 | |||
| 152 | /** |
||
| 153 | * Fix 'ON' clause |
||
| 154 | * |
||
| 155 | * @param mixed $onClause |
||
| 156 | * @return array|ExpressionInterface |
||
| 157 | * @access protected |
||
| 158 | */ |
||
| 159 | protected function fixOnClause($onClause) |
||
| 169 | |||
| 170 | /** |
||
| 171 | * Build join |
||
| 172 | * |
||
| 173 | * @param string $prefix |
||
| 174 | * @param array $settings |
||
| 175 | * @return string |
||
| 176 | * @access protected |
||
| 177 | */ |
||
| 178 | View Code Duplication | protected function buildJoin( |
|
| 195 | |||
| 196 | /** |
||
| 197 | * Build TABLE part |
||
| 198 | * |
||
| 199 | * @param array $cls |
||
| 200 | * @param array $settings |
||
| 201 | * @return string |
||
| 202 | * @access protected |
||
| 203 | */ |
||
| 204 | protected function buildJoinTable(array $cls, array $settings)/*# : string */ |
||
| 210 | |||
| 211 | /** |
||
| 212 | * Build ON part |
||
| 213 | * |
||
| 214 | * @param array $cls |
||
| 215 | * @param array $settings |
||
| 216 | * @return string |
||
| 217 | * @access protected |
||
| 218 | */ |
||
| 219 | protected function buildJoinOn(array $cls, array $settings)/*# : string */ |
||
| 240 | |||
| 241 | /** |
||
| 242 | * Get first table alias |
||
| 243 | * |
||
| 244 | * @param string $left left part of eq |
||
| 245 | * @return string |
||
| 246 | * @access protected |
||
| 247 | */ |
||
| 248 | protected function getFirstTableAlias( |
||
| 260 | |||
| 261 | /** |
||
| 262 | * Get second table alias |
||
| 263 | * |
||
| 264 | * @param array $cls |
||
| 265 | * @param string $right right part of eq |
||
| 266 | * @return string |
||
| 267 | * @access protected |
||
| 268 | */ |
||
| 269 | protected function getSecondTableAlias( |
||
| 283 | } |
||
| 284 |