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 |
||
| 6 | class Except { |
||
| 7 | private $pathPatterns; |
||
| 8 | |||
| 9 | /** |
||
| 10 | * Constructor |
||
| 11 | * |
||
| 12 | * @param array|string $patterns List or a single regex pattern to match |
||
|
|
|||
| 13 | */ |
||
| 14 | public function __construct($pathPatterns) { |
||
| 23 | |||
| 24 | /** |
||
| 25 | * Constructor |
||
| 26 | * |
||
| 27 | * @param array $pluginsDirectories Names of plugin folders to watch for |
||
| 28 | * Notices & Warnings. |
||
| 29 | */ |
||
| 30 | View Code Duplication | public static function pluginsDirectories($plugins) { |
|
| 43 | |||
| 44 | /** |
||
| 45 | * Constructor |
||
| 46 | * |
||
| 47 | * @param array $themesDirectories Names of theme folders to watch for |
||
| 48 | * Notices and Warnings. |
||
| 49 | */ |
||
| 50 | View Code Duplication | public static function themesDirectories() { |
|
| 63 | |||
| 64 | /** |
||
| 65 | * Constructor |
||
| 66 | */ |
||
| 67 | public static function blank() { |
||
| 70 | |||
| 71 | public function empty() { |
||
| 74 | |||
| 75 | public function pathPatterns() { |
||
| 78 | } |
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.