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 |
||
10 | class Execution |
||
11 | { |
||
12 | /** |
||
13 | * @var Client |
||
14 | */ |
||
15 | private $client; |
||
16 | |||
17 | /** |
||
18 | * @param Client $client |
||
19 | */ |
||
20 | public function __construct(Client $client) |
||
24 | |||
25 | /** |
||
26 | * @param string $id |
||
27 | * @return PromiseInterface |
||
28 | */ |
||
29 | public function info(string $id): PromiseInterface |
||
35 | |||
36 | /** |
||
37 | * @param string $id |
||
38 | * @return PromiseInterface |
||
39 | */ |
||
40 | public function delete(string $id): PromiseInterface |
||
46 | |||
47 | /** |
||
48 | * @param int[] $ids |
||
49 | * @return PromiseInterface |
||
50 | */ |
||
51 | public function bulkDelete(array $ids): PromiseInterface |
||
57 | |||
58 | /** |
||
59 | * @param string $id |
||
60 | * @return PromiseInterface |
||
61 | */ |
||
62 | public function state(string $id): PromiseInterface |
||
68 | |||
69 | /** |
||
70 | * @param string $id |
||
71 | * @param array $params |
||
72 | * @return PromiseInterface |
||
73 | */ |
||
74 | View Code Duplication | public function abort(string $id, array $params = []): PromiseInterface |
|
84 | |||
85 | /** |
||
86 | * @return Output |
||
87 | */ |
||
88 | public function output(): Output |
||
92 | } |
||
93 |
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.