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 |
||
| 19 | class LocalDateMapper extends AbstractPropertyMapper |
||
| 20 | { |
||
| 21 | /** @var AsLocalDate */ |
||
| 22 | private $options; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * C'tor. |
||
| 26 | * |
||
| 27 | * @param AsLocalDate $options |
||
| 28 | */ |
||
| 29 | public function __construct(AsLocalDate $options) |
||
| 33 | |||
| 34 | /** |
||
| 35 | * @return AsLocalDate |
||
| 36 | */ |
||
| 37 | public function getOptions() |
||
| 41 | |||
| 42 | /** |
||
| 43 | * @param Slumberer $slumberer |
||
| 44 | * @param mixed $value |
||
| 45 | * |
||
| 46 | * @return array |
||
| 47 | */ |
||
| 48 | 21 | View Code Duplication | public function slumber(Slumberer $slumberer, $value) |
| 59 | |||
| 60 | /** |
||
| 61 | * @param Awaker $awaker |
||
| 62 | * @param mixed $value |
||
| 63 | * |
||
| 64 | * @return LocalDate |
||
| 65 | */ |
||
| 66 | 17 | public function awake(Awaker $awaker, $value) |
|
| 88 | } |
||
| 89 |
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.