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 |
||
22 | class Translation extends HttpApi |
||
23 | { |
||
24 | /** |
||
25 | * Index a locale. |
||
26 | * |
||
27 | * @param string $projectKey |
||
28 | * @param string $localeId |
||
29 | * @param array $params |
||
30 | * |
||
31 | * @throws ClientExceptionInterface |
||
32 | * @throws DomainException |
||
33 | * |
||
34 | * @return Index|ResponseInterface |
||
35 | */ |
||
36 | View Code Duplication | public function indexLocale(string $projectKey, string $localeId, array $params = []) |
|
55 | |||
56 | /** |
||
57 | * Create a translation. |
||
58 | * |
||
59 | * @param string $projectKey |
||
60 | * @param string $localeId |
||
61 | * @param string $keyId |
||
62 | * @param string $content |
||
63 | * @param array $params |
||
64 | * |
||
65 | * @throws ClientExceptionInterface |
||
66 | * @throws DomainException |
||
67 | * |
||
68 | * @return TranslationCreated|ResponseInterface |
||
69 | */ |
||
70 | public function create(string $projectKey, string $localeId, string $keyId, string $content, array $params = []) |
||
88 | |||
89 | /** |
||
90 | * Update a translation. |
||
91 | * |
||
92 | * @param string $projectKey |
||
93 | * @param string $translationId |
||
94 | * @param string $content |
||
95 | * @param array $params |
||
96 | * |
||
97 | * @throws ClientExceptionInterface |
||
98 | * @throws DomainException |
||
99 | * |
||
100 | * @return TranslationUpdated|ResponseInterface |
||
101 | */ |
||
102 | View Code Duplication | public function update(string $projectKey, string $translationId, string $content, array $params = []) |
|
118 | |||
119 | /** |
||
120 | * List translations for a specific key. |
||
121 | * |
||
122 | * @param string $projectKey |
||
123 | * @param string $keyId |
||
124 | * @param array $params |
||
125 | * |
||
126 | * @throws ClientExceptionInterface |
||
127 | * @throws DomainException |
||
128 | * |
||
129 | * @return Index|ResponseInterface |
||
130 | */ |
||
131 | View Code Duplication | public function indexKey(string $projectKey, string $keyId, array $params = []) |
|
150 | } |
||
151 |
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.