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 | final class Variant extends HttpApi |
||
23 | { |
||
24 | /** |
||
25 | * @throws Exception\DomainException |
||
26 | * |
||
27 | * @return ResponseInterface|VariantCollection |
||
28 | */ |
||
29 | View Code Duplication | public function getAll(string $productCode, array $params = []) |
|
43 | |||
44 | /** |
||
45 | * {@link https://docs.sylius.com/en/1.3/api/product_variants.html#getting-a-single-product-variant}. |
||
46 | * |
||
47 | * @throws Exception |
||
48 | * |
||
49 | * @return Model|ResponseInterface |
||
50 | */ |
||
51 | View Code Duplication | public function get(string $productCode, string $code) |
|
65 | |||
66 | /** |
||
67 | * {@link https://docs.sylius.com/en/1.3/api/product_variants.html#creating-a-product-variant}. |
||
68 | * |
||
69 | * @throws Exception |
||
70 | * |
||
71 | * @return Model|ResponseInterface |
||
72 | */ |
||
73 | public function create(string $productCode, string $code, array $params = []) |
||
88 | |||
89 | /** |
||
90 | * Update a product partially. |
||
91 | * |
||
92 | * {@link https://docs.sylius.com/en/1.3/api/product_variants.html#updating-product-variant} |
||
93 | * |
||
94 | * @throws Exception |
||
95 | * |
||
96 | * @return void|ResponseInterface |
||
97 | */ |
||
98 | View Code Duplication | public function update(string $productCode, string $code, array $params = []) |
|
110 | |||
111 | /** |
||
112 | * {@link https://docs.sylius.com/en/1.3/api/product_variants.html#deleting-a-product-variant}. |
||
113 | * |
||
114 | * @throws Exception |
||
115 | * |
||
116 | * @return void|ResponseInterface |
||
117 | */ |
||
118 | View Code Duplication | public function delete(string $productCode, string $code) |
|
130 | } |
||
131 |
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.