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 |
||
7 | class MasterPoolConnection extends Connection |
||
8 | { |
||
9 | /** |
||
10 | * @TODO DESCR |
||
11 | */ |
||
12 | const STATE_CONTENT = 1; |
||
13 | /** @var array */ |
||
14 | public $instancesCount = []; |
||
15 | /** @var null */ |
||
16 | protected $timeout = null; // initial value of the minimal amout of bytes in buffer |
||
17 | /** @var int */ |
||
18 | protected $lowMark = 4; // initial value of the maximum amout of bytes in buffer |
||
19 | /** @var int */ |
||
20 | protected $highMark = 0xFFFF; |
||
21 | /** @var */ |
||
22 | protected $workerId; |
||
23 | /** @var */ |
||
24 | protected $packetLength; |
||
25 | |||
26 | /** |
||
27 | * @TODO DESCR |
||
28 | */ |
||
29 | public function onFinish() |
||
34 | |||
35 | /** |
||
36 | * @TODO DESCR |
||
37 | * @param $p |
||
38 | */ |
||
39 | public function sendPacket($p) |
||
44 | |||
45 | /** |
||
46 | * Called when new data received. |
||
47 | * @return void |
||
48 | */ |
||
49 | View Code Duplication | public function onRead() |
|
71 | |||
72 | /** |
||
73 | * @param $p |
||
74 | */ |
||
75 | protected function onPacket($p) |
||
114 | } |
||
115 |
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.