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 |
||
6 | class Request implements Frame{ |
||
7 | |||
8 | const CONSISTENCY_ANY = 0x0000; |
||
9 | const CONSISTENCY_ONE = 0x0001; |
||
10 | const CONSISTENCY_TWO = 0x0002; |
||
11 | const CONSISTENCY_THREE = 0x0003; |
||
12 | const CONSISTENCY_QUORUM = 0x0004; |
||
13 | const CONSISTENCY_ALL = 0x0005; |
||
14 | const CONSISTENCY_LOCAL_QUORUM = 0x0006; |
||
15 | const CONSISTENCY_EACH_QUORUM = 0x0007; |
||
16 | const CONSISTENCY_SERIAL = 0x0008; |
||
17 | const CONSISTENCY_LOCAL_SERIAL = 0x0009; |
||
18 | const CONSISTENCY_LOCAL_ONE = 0x000A; |
||
19 | |||
20 | /** |
||
21 | * @var int |
||
22 | */ |
||
23 | protected $version = 0x03; |
||
24 | |||
25 | /** |
||
26 | * @var int |
||
27 | */ |
||
28 | protected $opcode; |
||
29 | |||
30 | /** |
||
31 | * @var int |
||
32 | */ |
||
33 | protected $stream = 0; |
||
34 | |||
35 | /** |
||
36 | * @var int |
||
37 | */ |
||
38 | protected $flags = 0; |
||
39 | |||
40 | /** |
||
41 | * @param int $opcode |
||
42 | * @param int $stream |
||
43 | * @param int $flags |
||
44 | */ |
||
45 | public function __construct($opcode, $stream = 0, $flags = 0) { |
||
50 | |||
51 | public function getVersion(){ |
||
54 | |||
55 | public function getFlags(){ |
||
58 | |||
59 | public function getStream(){ |
||
62 | |||
63 | public function getOpcode(){ |
||
66 | |||
67 | public function getBody(){ |
||
70 | |||
71 | public function setStream($stream){ |
||
74 | |||
75 | /** |
||
76 | * @return string |
||
77 | */ |
||
78 | public function __toString(){ |
||
89 | |||
90 | /** |
||
91 | * |
||
92 | * @param array $values |
||
93 | * @throws Type\Exception |
||
94 | * @return string |
||
95 | */ |
||
96 | public static function valuesBinary(array $values, $namesForValues = false) { |
||
139 | |||
140 | /** |
||
141 | * |
||
142 | * @param array $values |
||
143 | * @param array $columns |
||
144 | * @return array |
||
145 | */ |
||
146 | public static function strictTypeValues(array $values, array $columns) { |
||
164 | |||
165 | /** |
||
166 | * |
||
167 | * @param int $consistency |
||
168 | * @param array $values |
||
169 | * @param array $options |
||
170 | * @return string |
||
171 | */ |
||
172 | public static function queryParameters($consistency, array $values = [], array $options = []){ |
||
209 | } |
||
210 |
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.