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 | class AutoScheduler extends AbstractScheduler |
||
12 | { |
||
13 | /** |
||
14 | * Constructor. |
||
15 | * Initialize cURL multi handle. |
||
16 | * @param CoOption $options |
||
17 | * @param resource $mh curl_multi |
||
18 | */ |
||
19 | public function __construct(CoOption $options, $mh) |
||
25 | |||
26 | /** |
||
27 | * Call curl_multi_add_handle(). |
||
28 | * @param resource $ch |
||
29 | * @param Deferred $deferred |
||
30 | */ |
||
31 | View Code Duplication | public function add($ch, Deferred $deferred = null) |
|
44 | |||
45 | /** |
||
46 | * Are there no cURL handles? |
||
47 | * @return bool |
||
48 | */ |
||
49 | public function isEmpty() |
||
53 | |||
54 | /** |
||
55 | * Do nothing. |
||
56 | * @param array $entry |
||
57 | */ |
||
58 | protected function interruptConsume(array $entry) {} |
||
59 | } |
||
60 |
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.