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 |
||
| 21 | class RecordsWindowFactory extends WindowFactory |
||
| 22 | { |
||
| 23 | /** @var Record[] */ |
||
| 24 | protected $recordsData = []; |
||
| 25 | |||
| 26 | /** @var GridBuilderFactory */ |
||
| 27 | protected $gridBuilderFactory; |
||
| 28 | |||
| 29 | /** @var DataCollectionFactory */ |
||
| 30 | protected $dataCollectionFactory; |
||
| 31 | |||
| 32 | /** @var Time */ |
||
| 33 | protected $timeFormatter; |
||
| 34 | |||
| 35 | /** |
||
| 36 | * @inheritdoc |
||
| 37 | */ |
||
| 38 | protected function createContent(ManialinkInterface $manialink) |
||
| 67 | |||
| 68 | /** |
||
| 69 | * @inheritdoc |
||
| 70 | */ |
||
| 71 | View Code Duplication | protected function updateContent(ManialinkInterface $manialink) |
|
| 84 | |||
| 85 | /** |
||
| 86 | * @return array |
||
| 87 | */ |
||
| 88 | protected function getRecordsData() |
||
| 103 | |||
| 104 | /** |
||
| 105 | * @param GridBuilderFactory $gridBuilderFactory |
||
| 106 | */ |
||
| 107 | public function setGridBuilderFactory($gridBuilderFactory) |
||
| 111 | |||
| 112 | /** |
||
| 113 | * @param DataCollectionFactory $dataCollectionFactory |
||
| 114 | */ |
||
| 115 | public function setDataCollectionFactory($dataCollectionFactory) |
||
| 119 | |||
| 120 | /** |
||
| 121 | * @param Time $time |
||
| 122 | */ |
||
| 123 | public function setTimerFormatter(Time $time) |
||
| 127 | |||
| 128 | /** |
||
| 129 | * @param Record[] $records |
||
| 130 | */ |
||
| 131 | public function setRecordsData($records) |
||
| 135 | } |
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.