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 |
||
| 12 | class RegExExistsRule extends StandardRule |
||
| 13 | { |
||
| 14 | private $regExs; |
||
| 15 | |||
| 16 | protected $contentTypes = array('text/html', 'application/json', 'application/xml'); |
||
| 17 | |||
| 18 | /** |
||
| 19 | * @param int $string The string that the document must contain |
||
|
|
|||
| 20 | */ |
||
| 21 | public function init(array $regExs) |
||
| 36 | |||
| 37 | /** |
||
| 38 | * @param ResponseInterface $response |
||
| 39 | * @throws ValidationFailedException |
||
| 40 | */ |
||
| 41 | protected function doValidation(ResponseInterface $response) |
||
| 71 | } |
||
| 72 |
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.