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 | View Code Duplication | class Sell extends Endpoint |
|
|
|||
6 | { |
||
7 | /** |
||
8 | * Determine if the request need authorized. |
||
9 | * |
||
10 | * @var bool |
||
11 | */ |
||
12 | protected $authorize = true; |
||
13 | |||
14 | /** |
||
15 | * Get the request url. |
||
16 | * |
||
17 | * @return string |
||
18 | */ |
||
19 | public function getUrl() |
||
23 | |||
24 | /** |
||
25 | * Get the request method. |
||
26 | * |
||
27 | * @return string |
||
28 | */ |
||
29 | public function getMethod() |
||
33 | |||
34 | /** |
||
35 | * Get the request data. |
||
36 | * |
||
37 | * @return array |
||
38 | */ |
||
39 | public function getData() |
||
50 | |||
51 | /** |
||
52 | * Map the given array to create a response object. |
||
53 | * |
||
54 | * @param array $data |
||
55 | * @return array |
||
56 | */ |
||
57 | public function mapResponse(array $data = []) |
||
70 | } |
||
71 |
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.