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 |
||
23 | Class File extends Package |
||
24 | { |
||
25 | /** |
||
26 | * Add new file to Crowdin project. |
||
27 | * |
||
28 | * @param Languagefile $languagefile The translation file object |
||
29 | * @param string $type The type. |
||
30 | * @param string $branch The branch. |
||
31 | * |
||
32 | * @see https://crowdin.com/page/api/add-file |
||
33 | * @since 1.0 |
||
34 | * |
||
35 | * @return ResponseInterface |
||
36 | */ |
||
37 | 1 | public function add(Languagefile $languagefile, string $type = '', string $branch = '') : ResponseInterface |
|
62 | |||
63 | /** |
||
64 | * Upload latest version of your localization file to Crowdin. |
||
65 | * |
||
66 | * @param Languagefile $languagefile The translation file object |
||
67 | * @param string $branch The branch. |
||
68 | * |
||
69 | * @see https://crowdin.com/page/api/update-file |
||
70 | * @since 1.0 |
||
71 | * |
||
72 | * @return ResponseInterface |
||
73 | */ |
||
74 | 1 | View Code Duplication | public function update(Languagefile $languagefile, $branch = '') : ResponseInterface |
91 | |||
92 | /** |
||
93 | * Delete file from Crowdin project. All the translations will be lost without ability to restore them. |
||
94 | * |
||
95 | * @param Languagefile $file The file to delete. |
||
96 | * |
||
97 | * @see https://crowdin.com/page/api/delete-file |
||
98 | * @since 1.0 |
||
99 | * |
||
100 | * @return ResponseInterface |
||
101 | */ |
||
102 | 1 | public function delete(Languagefile $file) : ResponseInterface |
|
107 | |||
108 | /** |
||
109 | * This method exports single translated files from Crowdin. |
||
110 | * Additionally, it can be applied to export XLIFF files for offline localization. |
||
111 | * |
||
112 | * @param string $file The file name. |
||
113 | * @param string $language The language tag. |
||
114 | * @param string $toPath Export to path. |
||
115 | * @param bool $xliff Export in xliff ext. |
||
116 | * |
||
117 | * @see https://crowdin.com/page/api/export-file |
||
118 | * @since 1.0 |
||
119 | * |
||
120 | * @return ResponseInterface |
||
121 | */ |
||
122 | 1 | public function export(string $file, string $language, string $toPath, bool $xliff = false) : ResponseInterface |
|
137 | |||
138 | /** |
||
139 | * Process a language file. |
||
140 | * |
||
141 | * @param array $data Data array. |
||
142 | * @param Languagefile $languagefile The language file object. |
||
143 | * |
||
144 | * @return array |
||
145 | */ |
||
146 | 1 | private function processLanguageFile(array $data, Languagefile $languagefile) : array |
|
171 | } |
||
172 |
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.