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 |
||
| 23 | class OneParameterCommand extends AbstractConnectionCommand |
||
| 24 | { |
||
| 25 | /** |
||
| 26 | * Description of the parameter |
||
| 27 | * |
||
| 28 | * @var string |
||
| 29 | */ |
||
| 30 | protected $parameterDescription; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * Description of the command. |
||
| 34 | * |
||
| 35 | * @var string |
||
| 36 | */ |
||
| 37 | protected $description; |
||
| 38 | |||
| 39 | /** |
||
| 40 | * Message to display in chat. |
||
| 41 | * |
||
| 42 | * @var string |
||
| 43 | */ |
||
| 44 | protected $chatMessage; |
||
| 45 | |||
| 46 | /** |
||
| 47 | * Name of the dedicated function to call. |
||
| 48 | * |
||
| 49 | * @var string |
||
| 50 | */ |
||
| 51 | protected $functionName; |
||
| 52 | |||
| 53 | /** |
||
| 54 | * OneParameterCommand constructor. |
||
| 55 | * |
||
| 56 | * @param $command |
||
| 57 | * @param string $permission |
||
| 58 | * @param array $aliases |
||
| 59 | * @param string $functionName |
||
| 60 | * @param string $parameterDescription |
||
| 61 | * @param AdminGroups $adminGroupsHelper |
||
| 62 | * @param Connection $connection |
||
|
|
|||
| 63 | * @param ChatNotification $chatNotification |
||
| 64 | * @param PlayerStorage $playerStorage |
||
| 65 | * @param LoggerInterface $logger |
||
| 66 | * @param Time $timeHelper |
||
| 67 | */ |
||
| 68 | 1 | View Code Duplication | public function __construct( |
| 69 | $command, |
||
| 70 | $permission, |
||
| 71 | array $aliases = [], |
||
| 72 | $functionName, |
||
| 73 | $parameterDescription, |
||
| 74 | AdminGroups $adminGroupsHelper, |
||
| 75 | Factory $factory, |
||
| 76 | ChatNotification $chatNotification, |
||
| 77 | PlayerStorage $playerStorage, |
||
| 78 | LoggerInterface $logger, |
||
| 79 | Time $timeHelper |
||
| 80 | ) { |
||
| 81 | 1 | parent::__construct( |
|
| 82 | 1 | $command, |
|
| 83 | $permission, |
||
| 84 | $aliases, |
||
| 85 | $adminGroupsHelper, |
||
| 86 | $factory, |
||
| 87 | $chatNotification, |
||
| 88 | $playerStorage, |
||
| 89 | $logger, |
||
| 90 | $timeHelper |
||
| 91 | ); |
||
| 92 | |||
| 93 | 1 | $this->description = 'expansion_admin_chat.'.strtolower($functionName).'.description'; |
|
| 94 | 1 | $this->chatMessage = 'expansion_admin_chat.'.strtolower($functionName).'.msg'; |
|
| 95 | 1 | $this->functionName = (string) $functionName; |
|
| 96 | 1 | $this->parameterDescription = (string) $parameterDescription; |
|
| 97 | 1 | } |
|
| 98 | |||
| 99 | |||
| 100 | /** |
||
| 101 | * @inheritdoc |
||
| 102 | */ |
||
| 103 | 1 | protected function configure() |
|
| 111 | |||
| 112 | /** |
||
| 113 | * @inheritdoc |
||
| 114 | */ |
||
| 115 | 1 | View Code Duplication | public function execute($login, InputInterface $input) |
| 139 | } |
||
| 140 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italyis not defined by the methodfinale(...).The most likely cause is that the parameter was removed, but the annotation was not.