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 |
||
24 | class CustomerPasswordChangeRequest extends AbstractApiRequest |
||
25 | { |
||
26 | const ID = 'id'; |
||
27 | const VERSION = 'version'; |
||
28 | const CURRENT_PASSWORD = 'currentPassword'; |
||
29 | const NEW_PASSWORD = 'newPassword'; |
||
30 | |||
31 | protected $resultClass = '\Commercetools\Core\Model\Customer\Customer'; |
||
32 | |||
33 | /** |
||
34 | * @var string |
||
35 | */ |
||
36 | protected $id; |
||
37 | |||
38 | /** |
||
39 | * @var int |
||
40 | */ |
||
41 | protected $version; |
||
42 | |||
43 | /** |
||
44 | * @var string |
||
45 | */ |
||
46 | protected $currentPassword; |
||
47 | |||
48 | /** |
||
49 | * @var string |
||
50 | */ |
||
51 | protected $newPassword; |
||
52 | |||
53 | /** |
||
54 | * @param string $id |
||
55 | * @param int $version |
||
56 | * @param string $currentPassword |
||
57 | * @param string $newPassword |
||
58 | * @param Context $context |
||
59 | */ |
||
60 | 6 | View Code Duplication | public function __construct($id, $version, $currentPassword, $newPassword, Context $context = null) |
68 | |||
69 | /** |
||
70 | * @param string $id |
||
71 | * @param int $version |
||
72 | * @param string $currentPassword |
||
73 | * @param string $newPassword |
||
74 | * @param Context $context |
||
75 | * @return static |
||
76 | */ |
||
77 | 6 | public static function ofIdVersionAndPasswords( |
|
86 | |||
87 | /** |
||
88 | * @return string |
||
89 | * @internal |
||
90 | */ |
||
91 | 6 | protected function getPath() |
|
95 | |||
96 | /** |
||
97 | * @return JsonRequest |
||
98 | * @internal |
||
99 | */ |
||
100 | 6 | public function httpRequest() |
|
110 | |||
111 | /** |
||
112 | * @param ResponseInterface $response |
||
113 | * @return ResourceResponse |
||
114 | * @internal |
||
115 | */ |
||
116 | 1 | public function buildResponse(ResponseInterface $response) |
|
120 | |||
121 | /** |
||
122 | * @return string |
||
123 | */ |
||
124 | 6 | public function getId() |
|
128 | |||
129 | /** |
||
130 | * @param string $id |
||
131 | * @return $this |
||
132 | */ |
||
133 | 6 | public function setId($id) |
|
139 | |||
140 | /** |
||
141 | * @return int |
||
142 | */ |
||
143 | 6 | public function getVersion() |
|
147 | |||
148 | /** |
||
149 | * @param int $version |
||
150 | * @return $this |
||
151 | */ |
||
152 | 6 | public function setVersion($version) |
|
158 | } |
||
159 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.