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 |
||
21 | class MePasswordChangeRequest extends AbstractApiRequest |
||
22 | { |
||
23 | const ID = 'id'; |
||
24 | const VERSION = 'version'; |
||
25 | const CURRENT_PASSWORD = 'currentPassword'; |
||
26 | const NEW_PASSWORD = 'newPassword'; |
||
27 | |||
28 | protected $resultClass = '\Commercetools\Core\Model\Customer\Customer'; |
||
29 | |||
30 | /** |
||
31 | * @var int |
||
32 | */ |
||
33 | protected $version; |
||
34 | |||
35 | /** |
||
36 | * @var string |
||
37 | */ |
||
38 | protected $currentPassword; |
||
39 | |||
40 | /** |
||
41 | * @var string |
||
42 | */ |
||
43 | protected $newPassword; |
||
44 | |||
45 | /** |
||
46 | * @param string $id |
||
|
|||
47 | * @param int $version |
||
48 | * @param string $currentPassword |
||
49 | * @param string $newPassword |
||
50 | * @param Context $context |
||
51 | */ |
||
52 | 2 | View Code Duplication | public function __construct($version, $currentPassword, $newPassword, Context $context = null) |
59 | |||
60 | /** |
||
61 | * @return int |
||
62 | */ |
||
63 | 2 | public function getVersion() |
|
67 | |||
68 | /** |
||
69 | * @param int $version |
||
70 | * @return $this |
||
71 | */ |
||
72 | 2 | public function setVersion($version) |
|
78 | |||
79 | /** |
||
80 | * @param int $version |
||
81 | * @param string $currentPassword |
||
82 | * @param string $newPassword |
||
83 | * @param Context $context |
||
84 | * @return static |
||
85 | */ |
||
86 | 2 | public static function ofVersionAndPasswords( |
|
94 | |||
95 | /** |
||
96 | * @return string |
||
97 | * @internal |
||
98 | */ |
||
99 | 2 | protected function getPath() |
|
103 | |||
104 | /** |
||
105 | * @return JsonRequest |
||
106 | * @internal |
||
107 | */ |
||
108 | 2 | public function httpRequest() |
|
117 | |||
118 | /** |
||
119 | * @param ResponseInterface $response |
||
120 | * @return ResourceResponse |
||
121 | * @internal |
||
122 | */ |
||
123 | 2 | public function buildResponse(ResponseInterface $response) |
|
127 | } |
||
128 |
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.