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 |
||
| 34 | class ConfigController extends OCSController { |
||
| 35 | |||
| 36 | /** @var string */ |
||
| 37 | protected $appName; |
||
| 38 | |||
| 39 | /** @var string */ |
||
| 40 | protected $serverRoot; |
||
| 41 | |||
| 42 | /** @var IConfig */ |
||
| 43 | private $config; |
||
| 44 | |||
| 45 | /** @var IUserSession */ |
||
| 46 | private $userSession; |
||
| 47 | |||
| 48 | /** @var AccessibilityProvider */ |
||
| 49 | private $accessibilityProvider; |
||
| 50 | |||
| 51 | /** |
||
| 52 | * Config constructor. |
||
| 53 | * |
||
| 54 | * @param string $appName |
||
| 55 | * @param IRequest $request |
||
| 56 | * @param IConfig $config |
||
| 57 | * @param IUserSession $userSession |
||
| 58 | * @param AccessibilityProvider $accessibilityProvider |
||
| 59 | */ |
||
| 60 | View Code Duplication | public function __construct(string $appName, |
|
| 71 | |||
| 72 | /** |
||
| 73 | * @NoAdminRequired |
||
| 74 | * |
||
| 75 | * Get user accessibility config |
||
| 76 | * |
||
| 77 | * @param string $key theme or font |
||
|
|
|||
| 78 | * @return DataResponse |
||
| 79 | */ |
||
| 80 | public function getConfig(): DataResponse { |
||
| 86 | |||
| 87 | /** |
||
| 88 | * @NoAdminRequired |
||
| 89 | * |
||
| 90 | * Set theme or font config |
||
| 91 | * |
||
| 92 | * @param string $key theme or font |
||
| 93 | * @return DataResponse |
||
| 94 | * @throws Exception |
||
| 95 | */ |
||
| 96 | public function setConfig(string $key, $value): DataResponse { |
||
| 120 | |||
| 121 | } |
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.