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 ReasonUserCommand extends AbstractConnectionCommand |
||
| 23 | { |
||
| 24 | /** |
||
| 25 | * Description of the login parameter |
||
| 26 | * |
||
| 27 | * @var string |
||
| 28 | */ |
||
| 29 | protected $parameterLoginDescription; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * Description of the reason parameter. |
||
| 33 | * |
||
| 34 | * @var string |
||
| 35 | */ |
||
| 36 | protected $parameterReasonDescription; |
||
| 37 | |||
| 38 | /** |
||
| 39 | * Description of the command. |
||
| 40 | * |
||
| 41 | * @var string |
||
| 42 | */ |
||
| 43 | protected $description; |
||
| 44 | |||
| 45 | /** |
||
| 46 | * Message to display in chat. |
||
| 47 | * |
||
| 48 | * @var string |
||
| 49 | */ |
||
| 50 | protected $chatMessage; |
||
| 51 | |||
| 52 | /** |
||
| 53 | * Name of the dedicated function to call. |
||
| 54 | * |
||
| 55 | * @var string |
||
| 56 | */ |
||
| 57 | protected $functionName; |
||
| 58 | |||
| 59 | /** |
||
| 60 | * ReasonUserCommand constructor. |
||
| 61 | * |
||
| 62 | * @param $command |
||
| 63 | * @param string $permission |
||
| 64 | * @param array $aliases |
||
| 65 | * @param AdminGroups $description |
||
|
|
|||
| 66 | * @param Connection $chatMessage |
||
| 67 | * @param ChatNotification $functionName |
||
| 68 | * @param PlayerStorage $parameterLoginDescription |
||
| 69 | * @param LoggerInterface $parameterReasonDescription |
||
| 70 | * @param AdminGroups $adminGroupsHelper |
||
| 71 | * @param Connection $connection |
||
| 72 | * @param ChatNotification $chatNotification |
||
| 73 | * @param PlayerStorage $playerStorage |
||
| 74 | * @param LoggerInterface $logger |
||
| 75 | * @param Time $timeHelper |
||
| 76 | */ |
||
| 77 | 1 | View Code Duplication | public function __construct( |
| 109 | |||
| 110 | |||
| 111 | /** |
||
| 112 | * @inheritdoc |
||
| 113 | */ |
||
| 114 | 1 | protected function configure() |
|
| 125 | |||
| 126 | |||
| 127 | /** |
||
| 128 | * @inheritdoc |
||
| 129 | */ |
||
| 130 | 1 | public function execute($login, InputInterface $input) |
|
| 152 | } |
||
| 153 |
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.