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 |
||
15 | final class GlobalOptOut extends Resource |
||
16 | { |
||
17 | const RESOURCE = 'accounts/{account_id}/tailored_audiences/{route}'; |
||
18 | |||
19 | // This is a hack to allow PUT requests for an entity without an ID |
||
20 | const RESOURCE_ID_REPLACE = '{route}'; |
||
21 | const ROUTE = 'global_opt_out'; |
||
22 | |||
23 | protected $input_file_path; |
||
24 | protected $list_type; |
||
25 | |||
26 | protected $properties = [ |
||
27 | 'input_file_path', |
||
28 | 'list type', |
||
29 | ]; |
||
30 | |||
31 | /** |
||
32 | * {@inheritdoc} |
||
33 | */ |
||
34 | public function getId() |
||
38 | |||
39 | public function getInputFilePath() |
||
43 | |||
44 | public function setInputFilePath($path) |
||
48 | |||
49 | /** |
||
50 | * @return mixed |
||
51 | */ |
||
52 | public function getListType() |
||
56 | |||
57 | /** |
||
58 | * @param string $type |
||
59 | */ |
||
60 | public function setListType($type) |
||
64 | |||
65 | /** |
||
66 | * Asserts that the given type is valid |
||
67 | * |
||
68 | * @param string $type |
||
69 | * @throws InvalidType - if type is invalid or null |
||
70 | * |
||
71 | * @return string |
||
72 | */ |
||
73 | View Code Duplication | private function assureValidType($type) |
|
85 | |||
86 | /** |
||
87 | * @return array |
||
88 | */ |
||
89 | public function getProperties() |
||
93 | } |
||
94 |
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.