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 |
||
| 5 | class MessageEcho extends Message |
||
| 6 | { |
||
| 7 | /** |
||
| 8 | * @var bool |
||
| 9 | */ |
||
| 10 | private $isEcho; |
||
| 11 | |||
| 12 | /** |
||
| 13 | * @var int |
||
| 14 | */ |
||
| 15 | private $appId; |
||
| 16 | |||
| 17 | /** |
||
| 18 | * @var null|string |
||
| 19 | */ |
||
| 20 | private $metadata; |
||
| 21 | |||
| 22 | /** |
||
| 23 | * MessageEcho constructor. |
||
| 24 | * |
||
| 25 | * @param bool $isEcho |
||
| 26 | * @param int $appId |
||
| 27 | * @param string $id |
||
| 28 | * @param int $sequence |
||
| 29 | * @param null|string $metadata |
||
| 30 | * @param null|string $text |
||
| 31 | * @param array $attachments |
||
| 32 | * @param null|string $quickReply |
||
|
|
|||
| 33 | */ |
||
| 34 | public function __construct($isEcho, $appId, $id, $sequence, $metadata = null, $text = null, array $attachments = []) |
||
| 41 | |||
| 42 | /** |
||
| 43 | * @return boolean |
||
| 44 | */ |
||
| 45 | public function isEcho() |
||
| 49 | |||
| 50 | /** |
||
| 51 | * @return int |
||
| 52 | */ |
||
| 53 | public function getAppId() |
||
| 57 | |||
| 58 | /** |
||
| 59 | * @return null|string |
||
| 60 | */ |
||
| 61 | public function getMetadata() |
||
| 65 | |||
| 66 | /** |
||
| 67 | * @param array $payload |
||
| 68 | * |
||
| 69 | * @return static |
||
| 70 | */ |
||
| 71 | View Code Duplication | public static function create(array $payload) |
|
| 79 | } |
||
| 80 |
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.