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 |
||
8 | class Batch extends Request{ |
||
9 | const TYPE_LOGGED = 0; |
||
10 | const TYPE_UNLOGGED = 1; |
||
11 | const TYPE_COUNTER = 2; |
||
12 | |||
13 | protected $opcode = Frame::OPCODE_BATCH; |
||
14 | |||
15 | /** |
||
16 | * @var array |
||
17 | */ |
||
18 | protected $_queryArray = []; |
||
19 | |||
20 | /** |
||
21 | * @var int |
||
22 | */ |
||
23 | protected $_batchType; |
||
24 | |||
25 | /** |
||
26 | * |
||
27 | * @var int |
||
28 | */ |
||
29 | protected $_consistency; |
||
30 | |||
31 | /** |
||
32 | * |
||
33 | * @var array |
||
34 | */ |
||
35 | protected $_options; |
||
36 | |||
37 | /** |
||
38 | * |
||
39 | * @param string $type |
||
40 | * @param string $consistency |
||
41 | * @param array $options |
||
42 | */ |
||
43 | public function __construct($type = null, $consistency = null, $options = []) { |
||
48 | |||
49 | /** |
||
50 | * Exec transaction |
||
51 | */ |
||
52 | public function getBody() { |
||
57 | |||
58 | /** |
||
59 | * @param string $cql |
||
60 | * @param array $values |
||
61 | * @return self |
||
62 | */ |
||
63 | View Code Duplication | public function appendQuery($cql, array $values = []) { |
|
73 | |||
74 | /** |
||
75 | * |
||
76 | * @param string $queryId |
||
77 | * @param array $values |
||
78 | * @return self |
||
79 | */ |
||
80 | View Code Duplication | public function appendQueryId($queryId, array $values = []) { |
|
90 | |||
91 | /** |
||
92 | * |
||
93 | * @param int $consistency |
||
94 | * @param array $options |
||
95 | * @return string |
||
96 | */ |
||
97 | public static function queryParameters($consistency, array $options = []){ |
||
122 | } |
||
123 |
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.