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 | abstract class AbstractConnectionCommand extends AbstractAdminChatCommand |
||
| 22 | { |
||
| 23 | /** @var Factory */ |
||
| 24 | protected $factory; |
||
| 25 | |||
| 26 | /** @var ChatNotification */ |
||
| 27 | protected $chatNotification; |
||
| 28 | |||
| 29 | /** @var PlayerStorage */ |
||
| 30 | protected $playerStorage; |
||
| 31 | |||
| 32 | /** @var LoggerInterface */ |
||
| 33 | protected $logger; |
||
| 34 | |||
| 35 | /** @var Time */ |
||
| 36 | protected $timeHelper; |
||
| 37 | |||
| 38 | /** |
||
| 39 | * Send chat output to public chat |
||
| 40 | * @var bool |
||
| 41 | */ |
||
| 42 | protected $isPublic = true; |
||
| 43 | |||
| 44 | /** |
||
| 45 | * AbstractConnectionCommand constructor. |
||
| 46 | * |
||
| 47 | * @param $command |
||
| 48 | * @param $permission |
||
| 49 | * @param array $aliases |
||
| 50 | * @param AdminGroups $adminGroupsHelper |
||
| 51 | * @param Factory $factory |
||
| 52 | * @param ChatNotification $chatNotification |
||
| 53 | * @param PlayerStorage $playerStorage |
||
| 54 | * @param LoggerInterface $logger |
||
| 55 | * @param Time $timeHelper |
||
| 56 | */ |
||
| 57 | View Code Duplication | public function __construct( |
|
| 76 | |||
| 77 | /** |
||
| 78 | * @param bool $bool chat output visibility |
||
| 79 | */ |
||
| 80 | public function setPublic($bool) |
||
| 84 | |||
| 85 | /** |
||
| 86 | * Get admin group Label |
||
| 87 | * |
||
| 88 | * @param string $login |
||
| 89 | * @return string |
||
| 90 | */ |
||
| 91 | View Code Duplication | public function getGroupLabel($login) |
|
| 104 | |||
| 105 | /** |
||
| 106 | * @return bool |
||
| 107 | */ |
||
| 108 | public function getPublic() |
||
| 112 | } |
||
| 113 |
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.