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 | class ReasonUserCommand extends AbstractConnectionCommand |
||
| 22 | { |
||
| 23 | /** |
||
| 24 | * Description of the login parameter |
||
| 25 | * |
||
| 26 | * @var string |
||
| 27 | */ |
||
| 28 | protected $parameterLoginDescription; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * Description of the reason parameter. |
||
| 32 | * |
||
| 33 | * @var string |
||
| 34 | */ |
||
| 35 | protected $parameterReasonDescription; |
||
| 36 | |||
| 37 | /** |
||
| 38 | * Description of the command. |
||
| 39 | * |
||
| 40 | * @var string |
||
| 41 | */ |
||
| 42 | protected $description; |
||
| 43 | |||
| 44 | /** |
||
| 45 | * Message to display in chat. |
||
| 46 | * |
||
| 47 | * @var string |
||
| 48 | */ |
||
| 49 | protected $chatMessage; |
||
| 50 | |||
| 51 | /** |
||
| 52 | * Name of the dedicated function to call. |
||
| 53 | * |
||
| 54 | * @var string |
||
| 55 | */ |
||
| 56 | protected $functionName; |
||
| 57 | |||
| 58 | /** |
||
| 59 | * ReasonUserCommand constructor. |
||
| 60 | * |
||
| 61 | * @param $command |
||
| 62 | * @param string $permission |
||
| 63 | * @param array $aliases |
||
| 64 | * @param AdminGroups $description |
||
|
|
|||
| 65 | * @param Connection $chatMessage |
||
| 66 | * @param ChatNotification $functionName |
||
| 67 | * @param PlayerStorage $parameterLoginDescription |
||
| 68 | * @param LoggerInterface $parameterReasonDescription |
||
| 69 | * @param AdminGroups $adminGroupsHelper |
||
| 70 | * @param Connection $connection |
||
| 71 | * @param ChatNotification $chatNotification |
||
| 72 | * @param PlayerStorage $playerStorage |
||
| 73 | * @param LoggerInterface $logger |
||
| 74 | * @param Time $timeHelper |
||
| 75 | */ |
||
| 76 | 1 | View Code Duplication | public function __construct( |
| 108 | |||
| 109 | |||
| 110 | /** |
||
| 111 | * @inheritdoc |
||
| 112 | */ |
||
| 113 | 1 | protected function configure() |
|
| 124 | |||
| 125 | |||
| 126 | /** |
||
| 127 | * @inheritdoc |
||
| 128 | */ |
||
| 129 | 1 | public function execute($login, InputInterface $input) |
|
| 153 | } |
||
| 154 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.
Consider the following example. The parameter
$irelandis not defined by the methodfinale(...).The most likely cause is that the parameter was changed, but the annotation was not.