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 |
||
5 | class Execute extends Request{ |
||
6 | |||
7 | protected $opcode = Frame::OPCODE_EXECUTE; |
||
8 | |||
9 | /** |
||
10 | * |
||
11 | * @var int |
||
12 | */ |
||
13 | protected $_queryId; |
||
14 | |||
15 | /** |
||
16 | * |
||
17 | * @var int |
||
18 | */ |
||
19 | protected $_consistency; |
||
20 | |||
21 | /** |
||
22 | * |
||
23 | * @var array |
||
24 | */ |
||
25 | protected $_values; |
||
26 | |||
27 | /** |
||
28 | * |
||
29 | * @var array |
||
30 | */ |
||
31 | protected $_options; |
||
32 | |||
33 | /** |
||
34 | * EXECUTE |
||
35 | * |
||
36 | * Executes a prepared query. The body of the message must be: |
||
37 | * <id><n><value_1>....<value_n><consistency> |
||
38 | * where: |
||
39 | * - <id> is the prepared query ID. It's the [short bytes] returned as a |
||
40 | * response to a PREPARE message. |
||
41 | * - <n> is a [short] indicating the number of following values. |
||
42 | * - <value_1>...<value_n> are the [bytes] to use for bound variables in the |
||
43 | * prepared query. |
||
44 | * - <consistency> is the [consistency] level for the operation. |
||
45 | * Note that the consistency is ignored by some (prepared) queries (USE, CREATE, |
||
46 | * ALTER, TRUNCATE, ...). |
||
47 | * The response from the server will be a RESULT message. |
||
48 | * |
||
49 | * @param int $queryId |
||
50 | * @param array $values |
||
51 | * @param int $consistency |
||
52 | * @param array $options |
||
53 | */ |
||
54 | View Code Duplication | public function __construct($queryId, array $values, $consistency = null, $options = []) { |
|
61 | |||
62 | public function getBody(){ |
||
69 | } |
||
70 |
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.