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 | abstract class Enum extends BaseEnum implements ValueObjectInterface |
||
9 | { |
||
10 | /** |
||
11 | * Returns a new Enum object from passed value matching argument |
||
12 | * |
||
13 | * @param string $value |
||
|
|||
14 | * @return static |
||
15 | */ |
||
16 | public static function fromNative() |
||
20 | |||
21 | /** |
||
22 | * Returns the PHP native value of the enum |
||
23 | * |
||
24 | * @return mixed |
||
25 | */ |
||
26 | 21 | public function toNative() |
|
30 | |||
31 | /** |
||
32 | * Tells whether two Enum objects are sameValueAs by comparing their values |
||
33 | * |
||
34 | * @param Enum $enum |
||
35 | * @return bool |
||
36 | */ |
||
37 | View Code Duplication | public function sameValueAs(ValueObjectInterface $enum) |
|
45 | |||
46 | /** |
||
47 | * Returns a native string representation of the Enum value |
||
48 | * |
||
49 | * @return string |
||
50 | */ |
||
51 | 6 | public function __toString() |
|
55 | } |
||
56 |
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
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.