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 | View Code Duplication | class MePasswordResetRequest extends AbstractApiRequest |
|
|
|||
22 | { |
||
23 | const TOKEN_VALUE = 'tokenValue'; |
||
24 | const NEW_PASSWORD = 'newPassword'; |
||
25 | |||
26 | protected $resultClass = '\Commercetools\Core\Model\Customer\Customer'; |
||
27 | |||
28 | /** |
||
29 | * @var string |
||
30 | */ |
||
31 | protected $token; |
||
32 | |||
33 | /** |
||
34 | * @var string |
||
35 | */ |
||
36 | protected $newPassword; |
||
37 | |||
38 | /** |
||
39 | * @param string $token |
||
40 | * @param string $newPassword |
||
41 | * @param Context $context |
||
42 | */ |
||
43 | 1 | public function __construct($token, $newPassword, Context $context = null) |
|
49 | |||
50 | /** |
||
51 | * @param string $token |
||
52 | * @param string $newPassword |
||
53 | * @param Context $context |
||
54 | * @return static |
||
55 | */ |
||
56 | 1 | public static function ofTokenAndPassword( |
|
63 | |||
64 | /** |
||
65 | * @return string |
||
66 | * @internal |
||
67 | */ |
||
68 | 1 | protected function getPath() |
|
72 | |||
73 | /** |
||
74 | * @return JsonRequest |
||
75 | * @internal |
||
76 | */ |
||
77 | 1 | public function httpRequest() |
|
85 | |||
86 | /** |
||
87 | * @param ResponseInterface $response |
||
88 | * @return ResourceResponse |
||
89 | * @internal |
||
90 | */ |
||
91 | 1 | public function buildResponse(ResponseInterface $response) |
|
95 | } |
||
96 |
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.