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 |
||
| 22 | class OneParameterCommand extends AbstractConnectionCommand |
||
| 23 | { |
||
| 24 | /** |
||
| 25 | * Description of the parameter |
||
| 26 | * |
||
| 27 | * @var string |
||
| 28 | */ |
||
| 29 | protected $parameterDescription; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * Description of the command. |
||
| 33 | * |
||
| 34 | * @var string |
||
| 35 | */ |
||
| 36 | protected $description; |
||
| 37 | |||
| 38 | /** |
||
| 39 | * Message to display in chat. |
||
| 40 | * |
||
| 41 | * @var string |
||
| 42 | */ |
||
| 43 | protected $chatMessage; |
||
| 44 | |||
| 45 | /** |
||
| 46 | * Name of the dedicated function to call. |
||
| 47 | * |
||
| 48 | * @var string |
||
| 49 | */ |
||
| 50 | protected $functionName; |
||
| 51 | |||
| 52 | /** |
||
| 53 | * OneParameterCommand constructor. |
||
| 54 | * |
||
| 55 | * @param $command |
||
| 56 | * @param string $permission |
||
| 57 | * @param array $aliases |
||
| 58 | * @param string $functionName |
||
| 59 | * @param string $parameterDescription |
||
| 60 | * @param AdminGroups $adminGroupsHelper |
||
| 61 | * @param Connection $connection |
||
| 62 | * @param ChatNotification $chatNotification |
||
| 63 | * @param PlayerStorage $playerStorage |
||
| 64 | * @param LoggerInterface $logger |
||
| 65 | * @param Time $timeHelper |
||
| 66 | */ |
||
| 67 | 1 | View Code Duplication | public function __construct( |
| 97 | |||
| 98 | |||
| 99 | /** |
||
| 100 | * @inheritdoc |
||
| 101 | */ |
||
| 102 | 1 | protected function configure() |
|
| 110 | |||
| 111 | /** |
||
| 112 | * @inheritdoc |
||
| 113 | */ |
||
| 114 | 1 | View Code Duplication | public function execute($login, InputInterface $input) |
| 138 | } |
||
| 139 |
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.