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 |
||
19 | class Asset extends HttpApi |
||
20 | { |
||
21 | /** |
||
22 | * Create an asset. |
||
23 | * {@link https://localise.biz/api/docs/assets/createasset}. |
||
24 | * |
||
25 | * @param string $projectKey |
||
26 | * @param string $id |
||
27 | * |
||
28 | * @return AssetModel|ResponseInterface |
||
29 | * |
||
30 | * @throws Exception |
||
31 | */ |
||
32 | public function create(string $projectKey, string $id) |
||
56 | |||
57 | /** |
||
58 | * Tag an asset. |
||
59 | * {@link https://localise.biz/api/docs/assets/tagasset}. |
||
60 | * |
||
61 | * @param string $projectKey |
||
62 | * @param string $id |
||
63 | * @param string $tag |
||
64 | * |
||
65 | * @return AssetModel|ResponseInterface |
||
66 | * |
||
67 | * @throws Exception\DomainException |
||
68 | */ |
||
69 | View Code Duplication | public function tag(string $projectKey, string $id, string $tag) |
|
86 | |||
87 | /** |
||
88 | * Patch an asset. |
||
89 | * {@link https://localise.biz/api/docs/assets/patchasset}. |
||
90 | * |
||
91 | * @param string $projectKey |
||
92 | * @param string $id |
||
93 | * @param string $type |
||
94 | * @param string $name |
||
95 | * @param string $context |
||
96 | * @param string $notes |
||
97 | * |
||
98 | * @return AssetModel|ResponseInterface |
||
99 | * |
||
100 | * @throws Exception |
||
101 | */ |
||
102 | public function patch(string $projectKey, string $id, $type = null, $name = null, $context = null, $notes = null) |
||
136 | } |
||
137 |
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.