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 declare(strict_types=1); |
||
| 46 | class GlobalScaleController extends BaseController { |
||
| 47 | |||
| 48 | |||
| 49 | use TStringTools; |
||
| 50 | use TAsync; |
||
| 51 | |||
| 52 | |||
| 53 | /** |
||
| 54 | * Event is generated by any instance of GS and sent to the instance that owns the Circles, that |
||
| 55 | * will broadcast the event to other if ok |
||
| 56 | * |
||
| 57 | * |
||
| 58 | * @PublicPage |
||
| 59 | * @NoCSRFRequired |
||
| 60 | * |
||
| 61 | * @param string $data |
||
|
|
|||
| 62 | * |
||
| 63 | * @return DataResponse |
||
| 64 | */ |
||
| 65 | View Code Duplication | public function event(): DataResponse { |
|
| 78 | |||
| 79 | |||
| 80 | /** |
||
| 81 | * Async process and broadcast the event to every instances of GS |
||
| 82 | * This should be initiated by the instance that owns the Circles. |
||
| 83 | * |
||
| 84 | * @PublicPage |
||
| 85 | * @NoCSRFRequired |
||
| 86 | * |
||
| 87 | * @param string $token |
||
| 88 | */ |
||
| 89 | public function asyncBroadcast(string $token) { |
||
| 108 | |||
| 109 | |||
| 110 | /** |
||
| 111 | * Event is sent by instance that owns the Circles. |
||
| 112 | * |
||
| 113 | * @PublicPage |
||
| 114 | * @NoCSRFRequired |
||
| 115 | * |
||
| 116 | * @param string $data |
||
| 117 | * |
||
| 118 | * @return DataResponse |
||
| 119 | */ |
||
| 120 | View Code Duplication | public function broadcast(): DataResponse { |
|
| 134 | |||
| 135 | } |
||
| 136 | |||
| 137 |
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.