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 |
||
| 8 | class MailDomain extends AbstractValidator |
||
| 9 | { |
||
| 10 | const FORBIDDEN = 'FORBIDDEN'; |
||
| 11 | |||
| 12 | protected $options = array( |
||
| 13 | 'file' => null, // File containing the authorized domains |
||
| 14 | ); |
||
| 15 | |||
| 16 | protected $messageTemplates = array( |
||
| 17 | self::FORBIDDEN => "This domain is not allowed", |
||
| 18 | ); |
||
| 19 | |||
| 20 | public function __construct($options = null) |
||
| 30 | |||
| 31 | /** |
||
| 32 | * Returns the file path |
||
| 33 | * |
||
| 34 | * @return int |
||
| 35 | */ |
||
| 36 | public function getFile() |
||
| 40 | |||
| 41 | /** |
||
| 42 | * Sets the path to the file |
||
| 43 | * |
||
| 44 | * @param string $path to the file |
||
|
|
|||
| 45 | * @return MailDomain Provides a fluent interface |
||
| 46 | * @throws Exception\InvalidArgumentException When file is not found |
||
| 47 | */ |
||
| 48 | View Code Duplication | public function setFile($file) |
|
| 57 | |||
| 58 | public function isValid($value) |
||
| 73 | } |
||
| 74 |
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.