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 | abstract class GridWindowFactory extends WindowFactory |
||
| 20 | { |
||
| 21 | /** @var array */ |
||
| 22 | protected $genericData = []; |
||
| 23 | |||
| 24 | /** @var GridBuilderFactory */ |
||
| 25 | protected $gridBuilderFactory; |
||
| 26 | |||
| 27 | /** @var DataCollectionFactory */ |
||
| 28 | protected $dataCollectionFactory; |
||
| 29 | |||
| 30 | /** @var Time */ |
||
| 31 | protected $timeFormatter; |
||
| 32 | |||
| 33 | /** |
||
| 34 | * @var |
||
| 35 | */ |
||
| 36 | protected $gridBuilder; |
||
| 37 | |||
| 38 | /** |
||
| 39 | * @inheritdoc |
||
| 40 | */ |
||
| 41 | protected function createContent(ManialinkInterface $manialink) |
||
| 46 | |||
| 47 | |||
| 48 | /** |
||
| 49 | * @param ManialinkInterface $manialink |
||
| 50 | * @return mixed |
||
| 51 | */ |
||
| 52 | abstract protected function createGrid(ManialinkInterface $manialink); |
||
| 53 | |||
| 54 | |||
| 55 | /** |
||
| 56 | * @inheritdoc |
||
| 57 | */ |
||
| 58 | View Code Duplication | protected function updateContent(ManialinkInterface $manialink) |
|
| 71 | |||
| 72 | /** |
||
| 73 | * @param array $data |
||
| 74 | */ |
||
| 75 | public function setData($data) |
||
| 79 | |||
| 80 | /** |
||
| 81 | * @return array |
||
| 82 | */ |
||
| 83 | public function getData() { |
||
| 86 | /** |
||
| 87 | * @param GridBuilderFactory $gridBuilderFactory |
||
| 88 | */ |
||
| 89 | public function setGridBuilderFactory($gridBuilderFactory) |
||
| 93 | |||
| 94 | /** |
||
| 95 | * @param DataCollectionFactory $dataCollectionFactory |
||
| 96 | */ |
||
| 97 | public function setDataCollectionFactory($dataCollectionFactory) |
||
| 101 | |||
| 102 | /** |
||
| 103 | * @param Time $time |
||
| 104 | */ |
||
| 105 | public function setTimerFormatter(Time $time) |
||
| 109 | |||
| 110 | |||
| 111 | } |
||
| 112 |
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.