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 |
||
| 13 | class Update extends BaseQuery |
||
| 14 | { |
||
| 15 | use SelectionTrait; |
||
| 16 | |||
| 17 | protected $data = []; |
||
| 18 | |||
| 19 | /** |
||
| 20 | * Set the data to update. |
||
| 21 | * |
||
| 22 | * @param array $data |
||
| 23 | * |
||
| 24 | * @return self |
||
| 25 | */ |
||
| 26 | public function data(array $data) |
||
| 32 | |||
| 33 | /** |
||
| 34 | * Adds new marks to the query. |
||
| 35 | * |
||
| 36 | * @param array $marks |
||
| 37 | * |
||
| 38 | * @return self |
||
| 39 | */ |
||
| 40 | public function marks(array $marks) |
||
| 46 | |||
| 47 | /** |
||
| 48 | * {@inheritdoc} |
||
| 49 | */ |
||
| 50 | View Code Duplication | public function __invoke() |
|
| 60 | |||
| 61 | /** |
||
| 62 | * {@inheritdoc} |
||
| 63 | */ |
||
| 64 | public function __toString() |
||
| 74 | |||
| 75 | /** |
||
| 76 | * Generates the data part of a UPDATE query. |
||
| 77 | * |
||
| 78 | * @param array $fields |
||
| 79 | * |
||
| 80 | * @return string |
||
| 81 | */ |
||
| 82 | View Code Duplication | protected static function buildFields(array $fields) |
|
| 92 | } |
||
| 93 |
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.