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 |
||
| 10 | abstract class Parameters extends ParameterBag |
||
| 11 | { |
||
| 12 | /** |
||
| 13 | * {@inheritdoc} |
||
| 14 | */ |
||
| 15 | 6 | public function __construct(array $parameters = array()) |
|
| 19 | |||
| 20 | /** |
||
| 21 | * @return array |
||
| 22 | */ |
||
| 23 | 2 | public function getParameters() |
|
| 27 | |||
| 28 | /** |
||
| 29 | * @return string $query |
||
| 30 | */ |
||
| 31 | 2 | public function getFilter() |
|
| 35 | |||
| 36 | /** |
||
| 37 | * @param string $query |
||
| 38 | * |
||
| 39 | * @return $this |
||
| 40 | */ |
||
| 41 | 2 | public function setFilter($query) |
|
| 47 | |||
| 48 | /** |
||
| 49 | * @param $lang |
||
| 50 | * |
||
| 51 | * @return self |
||
| 52 | */ |
||
| 53 | 1 | public function setLang($lang) |
|
| 59 | |||
| 60 | /** |
||
| 61 | * @return string |
||
| 62 | */ |
||
| 63 | 1 | public function getLang() |
|
| 67 | |||
| 68 | /** |
||
| 69 | * Get column prefix of a query |
||
| 70 | * |
||
| 71 | * @return string |
||
| 72 | */ |
||
| 73 | 2 | View Code Duplication | public function getFilterColumn() |
| 88 | |||
| 89 | /** |
||
| 90 | * @return string |
||
| 91 | */ |
||
| 92 | 2 | View Code Duplication | public function getFilterValue() |
| 106 | } |
||
| 107 |
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.