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 |
||
| 16 | class WidgetCurrentMap implements StatusAwarePluginInterface, ListenerInterfaceMpLegacyMap, ListenerInterfaceExpMapRatings |
||
| 17 | { |
||
| 18 | /** @var Connection */ |
||
| 19 | protected $connection; |
||
| 20 | /** |
||
| 21 | * @var PlayerStorage |
||
| 22 | */ |
||
| 23 | private $playerStorage; |
||
| 24 | /** |
||
| 25 | * @var CurrentMapWidgetFactory |
||
| 26 | */ |
||
| 27 | private $widget; |
||
| 28 | /** |
||
| 29 | * @var Group |
||
| 30 | */ |
||
| 31 | private $players; |
||
| 32 | |||
| 33 | /** |
||
| 34 | * Debug constructor. |
||
| 35 | * |
||
| 36 | * @param Connection $connection |
||
| 37 | * @param PlayerStorage $playerStorage |
||
| 38 | * @param CurrentMapWidgetFactory $widget |
||
| 39 | * @param Group $players |
||
| 40 | */ |
||
| 41 | View Code Duplication | public function __construct( |
|
| 52 | |||
| 53 | |||
| 54 | public function setStatus($status) |
||
| 62 | |||
| 63 | /** |
||
| 64 | * @param Map $map |
||
| 65 | * |
||
| 66 | * @return void |
||
| 67 | */ |
||
| 68 | public function onBeginMap(Map $map) |
||
| 72 | |||
| 73 | /** |
||
| 74 | * @param Map $map |
||
| 75 | * |
||
| 76 | * @return void |
||
| 77 | */ |
||
| 78 | public function onEndMap(Map $map) |
||
| 82 | |||
| 83 | /** |
||
| 84 | * Called when map ratings are loaded. |
||
| 85 | * |
||
| 86 | * @param Maprating[] $ratings |
||
| 87 | * @return void |
||
| 88 | */ |
||
| 89 | public function onMapRatingsLoaded($ratings) |
||
| 94 | |||
| 95 | /** |
||
| 96 | * Called when map ratings are changed. |
||
| 97 | * |
||
| 98 | * @param string $login |
||
| 99 | * @param int $score |
||
| 100 | * @param Maprating[] $ratings |
||
| 101 | * @return void |
||
| 102 | */ |
||
| 103 | public function onMapRatingsChanged($login, $score, $ratings) |
||
| 108 | } |
||
| 109 |
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.