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 |
||
| 17 | class RestartMapVote extends AbstractVote |
||
| 18 | { |
||
| 19 | /** @var JukeboxService */ |
||
| 20 | protected $jukebox; |
||
| 21 | |||
| 22 | /** @var MapStorage */ |
||
| 23 | protected $mapStorage; |
||
| 24 | |||
| 25 | /** @var ChatNotification */ |
||
| 26 | protected $chatNotification; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * NexMapVote constructor. |
||
| 30 | * |
||
| 31 | * @param Player $player |
||
| 32 | * @param string $type |
||
| 33 | * @param int $duration |
||
| 34 | * @param float $ration |
||
| 35 | * @param JukeboxService $jukebox |
||
| 36 | * @param MapStorage $mapStorage |
||
| 37 | * @param ChatNotification $chatNotification |
||
| 38 | */ |
||
| 39 | 3 | View Code Duplication | public function __construct( |
| 54 | |||
| 55 | |||
| 56 | /** |
||
| 57 | * @inheritdoc |
||
| 58 | */ |
||
| 59 | 1 | public function getQuestion(): string |
|
| 63 | |||
| 64 | /** |
||
| 65 | * @inheritdoc |
||
| 66 | */ |
||
| 67 | 1 | public function executeVotePassed() |
|
| 72 | |||
| 73 | /** |
||
| 74 | * @inheritdoc |
||
| 75 | */ |
||
| 76 | 1 | public function executeVoteFailed() |
|
| 80 | } |
||
| 81 |
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.