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 |
||
21 | final class Taxon extends HttpApi |
||
22 | { |
||
23 | /** |
||
24 | * {@link https://docs.sylius.com/en/1.4/api/taxons.html#collection-of-taxons}. |
||
25 | * |
||
26 | * @throws Exception\DomainException |
||
27 | * |
||
28 | * @return ResponseInterface|ModelCollection |
||
29 | */ |
||
30 | public function getAll(array $params = []) |
||
44 | |||
45 | /** |
||
46 | * {@link https://docs.sylius.com/en/1.4/api/taxons.html#getting-a-single-taxon}. |
||
47 | * |
||
48 | * @throws Exception |
||
49 | * |
||
50 | * @return Model|ResponseInterface |
||
51 | */ |
||
52 | public function get(string $code) |
||
66 | |||
67 | /** |
||
68 | * {@link https://docs.sylius.com/en/1.4/api/taxons.html#creating-a-taxon}. |
||
69 | * |
||
70 | * @throws Exception |
||
71 | * |
||
72 | * @return Model|ResponseInterface |
||
73 | */ |
||
74 | View Code Duplication | public function create(string $code, array $params = []) |
|
89 | |||
90 | /** |
||
91 | * Update a taxon partially. |
||
92 | * |
||
93 | * {@link https://docs.sylius.com/en/1.4/api/taxons.html#updating-taxon} |
||
94 | * |
||
95 | * @throws Exception |
||
96 | * |
||
97 | * @return ResponseInterface|void |
||
98 | */ |
||
99 | public function update(string $code, array $params = []) |
||
112 | |||
113 | /** |
||
114 | * {@link https://docs.sylius.com/en/1.4/api/taxons.html#deleting-a-taxon}. |
||
115 | * |
||
116 | * @throws Exception |
||
117 | * |
||
118 | * @return ResponseInterface|void |
||
119 | */ |
||
120 | public function delete(string $code) |
||
132 | |||
133 | private function validateAndGetParams(string $code, array $optionalParams): array |
||
145 | } |
||
146 |
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.