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 |
||
| 18 | class BestRecords implements StatusAwarePluginInterface, RecordsDataListener, ListenerInterfaceMpLegacyMap |
||
| 19 | { |
||
| 20 | /** @var Factory */ |
||
| 21 | protected $factory; |
||
| 22 | /** |
||
| 23 | * @var PlayerStorage |
||
| 24 | */ |
||
| 25 | private $playerStorage; |
||
| 26 | /** |
||
| 27 | * @var BestRecordsWidgetFactory |
||
| 28 | */ |
||
| 29 | private $widget; |
||
| 30 | /** |
||
| 31 | * @var Group |
||
| 32 | */ |
||
| 33 | private $players; |
||
| 34 | |||
| 35 | /** |
||
| 36 | * @var Group |
||
| 37 | */ |
||
| 38 | private $allPlayers; |
||
| 39 | |||
| 40 | |||
| 41 | /** |
||
| 42 | * Debug constructor. |
||
| 43 | * |
||
| 44 | * @param Connection $connection |
||
|
|
|||
| 45 | * @param PlayerStorage $playerStorage |
||
| 46 | * @param BestRecordsWidgetFactory $widget |
||
| 47 | * @param Group $players |
||
| 48 | * @param Group $allPlayers |
||
| 49 | */ |
||
| 50 | View Code Duplication | public function __construct( |
|
| 63 | |||
| 64 | /** |
||
| 65 | * Set the status of the plugin |
||
| 66 | * |
||
| 67 | * @param boolean $status |
||
| 68 | * |
||
| 69 | * @return void |
||
| 70 | */ |
||
| 71 | public function setStatus($status) |
||
| 81 | |||
| 82 | /** |
||
| 83 | * @inheritdoc |
||
| 84 | */ |
||
| 85 | public function onLocalRecordsLoaded($records, BaseRecords $baseRecords) |
||
| 98 | |||
| 99 | /** |
||
| 100 | * @inheritdoc |
||
| 101 | */ |
||
| 102 | View Code Duplication | public function onLocalRecordsFirstRecord(Record $record, $records, $position, BaseRecords $baseRecords) |
|
| 111 | |||
| 112 | /** |
||
| 113 | * @inheritdoc |
||
| 114 | */ |
||
| 115 | public function onLocalRecordsSameScore(Record $record, Record $oldRecord, $records, BaseRecords $baseRecords) |
||
| 119 | |||
| 120 | /** |
||
| 121 | * @inheritdoc |
||
| 122 | */ |
||
| 123 | View Code Duplication | public function onLocalRecordsBetterPosition(Record $record, Record $oldRecord, $records, $position, $oldPosition, BaseRecords $baseRecords) |
|
| 134 | |||
| 135 | /** |
||
| 136 | * @inheritdoc |
||
| 137 | */ |
||
| 138 | View Code Duplication | public function onLocalRecordsSamePosition(Record $record, Record $oldRecord, $records, $position, BaseRecords $baseRecords) |
|
| 149 | |||
| 150 | |||
| 151 | /** |
||
| 152 | * @param Map $map |
||
| 153 | * |
||
| 154 | * @return void |
||
| 155 | */ |
||
| 156 | public function onBeginMap(Map $map) |
||
| 160 | |||
| 161 | /** |
||
| 162 | * @param Map $map |
||
| 163 | * |
||
| 164 | * @return void |
||
| 165 | */ |
||
| 166 | public function onEndMap(Map $map) |
||
| 170 | |||
| 171 | /** |
||
| 172 | * Check if we can use the data for this plugin. |
||
| 173 | * |
||
| 174 | * @param BaseRecords $baseRecords |
||
| 175 | * |
||
| 176 | * @return bool |
||
| 177 | */ |
||
| 178 | protected function checkRecordPlugin(BaseRecords $baseRecords) |
||
| 182 | } |
||
| 183 |
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.