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 BancontactPayment extends Payment |
||
| 13 | { |
||
| 14 | /** |
||
| 15 | * @var \DateTime |
||
| 16 | */ |
||
| 17 | private $dueDate; |
||
| 18 | |||
| 19 | /** |
||
| 20 | * CreditCardPayment constructor. |
||
| 21 | * |
||
| 22 | * @param Money $money |
||
| 23 | * @param array $issuers |
||
|
|
|||
| 24 | * @param string $purchaseId |
||
| 25 | * @param \DateTime $expiryDate |
||
| 26 | */ |
||
| 27 | 1 | public function __construct(Money $money, $purchaseId, \DateTime $expiryDate = null) |
|
| 33 | |||
| 34 | /** @inheritdoc */ |
||
| 35 | 1 | View Code Duplication | public function toArray() |
| 47 | } |
||
| 48 |
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.