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 Connection extends ClientConnection |
||
12 | { |
||
13 | /** |
||
14 | * DESCR |
||
15 | */ |
||
16 | const STATE_DATA = 1; |
||
17 | |||
18 | /** |
||
19 | * @var mixed current result |
||
20 | */ |
||
21 | public $result; |
||
22 | |||
23 | /** |
||
24 | * @var string flags of incoming value |
||
25 | */ |
||
26 | public $valueFlags; |
||
27 | |||
28 | /** |
||
29 | * @var integer length of incoming value |
||
30 | */ |
||
31 | public $valueLength; |
||
32 | |||
33 | /** |
||
34 | * @var string error message |
||
35 | */ |
||
36 | public $error; |
||
37 | |||
38 | /** |
||
39 | * @var string current incoming key |
||
40 | */ |
||
41 | public $key; |
||
42 | |||
43 | /** |
||
44 | * @var string |
||
45 | */ |
||
46 | protected $EOL = "\r\n"; |
||
47 | |||
48 | /** |
||
49 | * @var integer |
||
50 | */ |
||
51 | protected $maxQueue = 10; |
||
52 | |||
53 | /** |
||
54 | * Called when new data received |
||
55 | * @return void |
||
56 | */ |
||
57 | protected function onRead() |
||
101 | } |
||
102 |
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.