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 |
||
| 18 | class AddressValidator |
||
| 19 | { |
||
| 20 | private $address; |
||
| 21 | |||
| 22 | /** |
||
| 23 | * AddressValidator constructor. |
||
| 24 | * @param Address $bankAccount |
||
|
|
|||
| 25 | */ |
||
| 26 | public function __construct(Address $address) |
||
| 30 | |||
| 31 | /** |
||
| 32 | * This validate the virtual card |
||
| 33 | */ |
||
| 34 | public function validate(): void |
||
| 44 | |||
| 45 | /** |
||
| 46 | * This validate a zip code |
||
| 47 | * |
||
| 48 | * @return void |
||
| 49 | * @throws InvalidArgumentException |
||
| 50 | */ |
||
| 51 | private function validateZipCode() |
||
| 58 | |||
| 59 | /** |
||
| 60 | * This validates a address |
||
| 61 | * |
||
| 62 | * @return void |
||
| 63 | * @throws InvalidArgumentException |
||
| 64 | */ |
||
| 65 | View Code Duplication | private function validateAddress() |
|
| 72 | |||
| 73 | /** |
||
| 74 | * This validate a address number |
||
| 75 | * |
||
| 76 | * @return void |
||
| 77 | * @throws InvalidArgumentException |
||
| 78 | */ |
||
| 79 | private function validateNumber() |
||
| 86 | |||
| 87 | /** |
||
| 88 | * This validate a virtual card neighborhood |
||
| 89 | * |
||
| 90 | * @return void |
||
| 91 | * @throws InvalidArgumentException |
||
| 92 | */ |
||
| 93 | View Code Duplication | private function validateNeighborhood() |
|
| 100 | |||
| 101 | /** |
||
| 102 | * This validate a virtual card city |
||
| 103 | * |
||
| 104 | * @return void |
||
| 105 | * @throws InvalidArgumentException |
||
| 106 | */ |
||
| 107 | View Code Duplication | private function validateCity() |
|
| 114 | |||
| 115 | /** |
||
| 116 | * This validate a virtual card state |
||
| 117 | * |
||
| 118 | * @return void |
||
| 119 | * @throws InvalidArgumentException |
||
| 120 | */ |
||
| 121 | View Code Duplication | private function validateState() |
|
| 128 | |||
| 129 | /** |
||
| 130 | * This validate a virtual card country |
||
| 131 | * |
||
| 132 | * @return void |
||
| 133 | * @throws InvalidArgumentException |
||
| 134 | */ |
||
| 135 | View Code Duplication | private function validateCountry() |
|
| 142 | } |
||
| 143 |
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.