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 |
||
| 30 | class JukeboxWindowFactory extends GridWindowFactory |
||
| 31 | { |
||
| 32 | public $sizeX; |
||
| 33 | public $sizeY; |
||
| 34 | |||
| 35 | /** @var GridBuilderFactory */ |
||
| 36 | protected $gridBuilderFactory; |
||
| 37 | |||
| 38 | /** @var DataCollectionFactory */ |
||
| 39 | protected $dataCollectionFactory; |
||
| 40 | |||
| 41 | /** @var Time */ |
||
| 42 | protected $timeFormatter; |
||
| 43 | /** |
||
| 44 | * @var Jukebox |
||
| 45 | */ |
||
| 46 | private $jukeboxPlugin; |
||
| 47 | /** |
||
| 48 | * @var JukeboxService |
||
| 49 | */ |
||
| 50 | private $jukeboxService; |
||
| 51 | /** |
||
| 52 | * @var AdminGroups |
||
| 53 | */ |
||
| 54 | private $adminGroups; |
||
| 55 | |||
| 56 | /** |
||
| 57 | * MapsWindowFactory constructor. |
||
| 58 | * @param $name |
||
| 59 | * @param $sizeX |
||
| 60 | * @param $sizeY |
||
| 61 | * @param null $posX |
||
| 62 | * @param null $posY |
||
| 63 | * @param WindowFactoryContext $context |
||
| 64 | * @param GridBuilderFactory $gridBuilderFactory |
||
| 65 | * @param DataCollectionFactory $dataCollectionFactory |
||
| 66 | * @param Time $time |
||
| 67 | * @param JukeboxService $jukeboxService |
||
| 68 | * @param AdminGroups $adminGroups |
||
| 69 | */ |
||
| 70 | View Code Duplication | public function __construct( |
|
|
|
|||
| 71 | $name, |
||
| 72 | $sizeX, |
||
| 73 | $sizeY, |
||
| 74 | $posX, |
||
| 75 | $posY, |
||
| 76 | WindowFactoryContext $context, |
||
| 77 | GridBuilderFactory $gridBuilderFactory, |
||
| 78 | DataCollectionFactory $dataCollectionFactory, |
||
| 79 | Time $time, |
||
| 80 | JukeboxService $jukeboxService, |
||
| 81 | AdminGroups $adminGroups |
||
| 82 | ) { |
||
| 83 | parent::__construct($name, $sizeX, $sizeY, $posX, $posY, $context); |
||
| 84 | |||
| 85 | $this->gridBuilderFactory = $gridBuilderFactory; |
||
| 86 | $this->dataCollectionFactory = $dataCollectionFactory; |
||
| 87 | $this->timeFormatter = $time; |
||
| 88 | $this->sizeX = $sizeX; |
||
| 89 | $this->sizeY = $sizeY; |
||
| 90 | $this->jukeboxService = $jukeboxService; |
||
| 91 | $this->adminGroups = $adminGroups; |
||
| 92 | } |
||
| 93 | |||
| 94 | public function setJukeboxPlugin(Jukebox $plugin) |
||
| 98 | |||
| 99 | /** |
||
| 100 | * @param ManialinkInterface $manialink |
||
| 101 | * @return void |
||
| 102 | */ |
||
| 103 | protected function createGrid(ManialinkInterface $manialink) |
||
| 146 | |||
| 147 | View Code Duplication | public function callbackClear(ManialinkInterface $manialink, $login, $entries, $args) |
|
| 154 | |||
| 155 | View Code Duplication | public function callbackDrop(ManialinkInterface $manialink, $login, $entries, $args) |
|
| 164 | |||
| 165 | View Code Duplication | public function callbackDropMap(ManialinkInterface $manialink, $login, $params, $args) |
|
| 172 | |||
| 173 | public function createContent(ManialinkInterface $manialink) |
||
| 194 | |||
| 195 | /** |
||
| 196 | * @return array |
||
| 197 | */ |
||
| 198 | public function updateMaps() |
||
| 219 | |||
| 220 | |||
| 221 | } |
||
| 222 |
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.