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 |
||
11 | View Code Duplication | class Child |
|
|
|||
12 | { |
||
13 | /** |
||
14 | * @var EventLoop |
||
15 | */ |
||
16 | protected $loop; |
||
17 | |||
18 | /** |
||
19 | * @var int |
||
20 | */ |
||
21 | protected $pid; |
||
22 | |||
23 | /** |
||
24 | * @var callable |
||
25 | */ |
||
26 | protected $callback; |
||
27 | |||
28 | /** |
||
29 | * @var int |
||
30 | */ |
||
31 | protected $priority; |
||
32 | |||
33 | public function __construct( |
||
44 | |||
45 | /** |
||
46 | * @return EventLoop |
||
47 | */ |
||
48 | public function getLoop() |
||
52 | |||
53 | /** |
||
54 | * @return int |
||
55 | */ |
||
56 | public function getPid() |
||
60 | |||
61 | /** |
||
62 | * @return callable |
||
63 | */ |
||
64 | public function getCallback() |
||
68 | |||
69 | /** |
||
70 | * @return int |
||
71 | */ |
||
72 | public function getPriority() |
||
76 | |||
77 | public function cancel() |
||
81 | } |
||
82 |
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.