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 |
||
| 20 | class OneParameterCommand extends AbstractConnectionCommand |
||
| 21 | { |
||
| 22 | /** |
||
| 23 | * Description of the parameter |
||
| 24 | * |
||
| 25 | * @var string |
||
| 26 | */ |
||
| 27 | protected $parameterDescription; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * Description of the command. |
||
| 31 | * |
||
| 32 | * @var string |
||
| 33 | */ |
||
| 34 | protected $description; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * Message to display in chat. |
||
| 38 | * |
||
| 39 | * @var string |
||
| 40 | */ |
||
| 41 | protected $chatMessage; |
||
| 42 | |||
| 43 | /** |
||
| 44 | * Name of the dedicated function to call. |
||
| 45 | * |
||
| 46 | * @var string |
||
| 47 | */ |
||
| 48 | protected $functionName; |
||
| 49 | |||
| 50 | /** |
||
| 51 | * OneParameterCommand constructor. |
||
| 52 | * |
||
| 53 | * @param $command |
||
| 54 | * @param string $permission |
||
| 55 | * @param array $aliases |
||
| 56 | * @param AdminGroups $description |
||
|
|
|||
| 57 | * @param Connection $chatMessage |
||
| 58 | * @param ChatNotification $functionName |
||
| 59 | * @param PlayerStorage $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) |
| 135 | } |
||
| 136 |
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.