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 |
||
13 | class SelectStatement extends Statement |
||
14 | { |
||
15 | /** |
||
16 | * @var array |
||
17 | */ |
||
18 | protected $fields = ['*']; |
||
19 | |||
20 | /** |
||
21 | * Adds fields to this statement. |
||
22 | * Supported input styles: |
||
23 | * - addFields('field1,field2') |
||
24 | * - addFields(['field','field2']). |
||
25 | * |
||
26 | * @param string|array $fields |
||
27 | * |
||
28 | * @return self |
||
29 | */ |
||
30 | View Code Duplication | public function addFields($fields) |
|
42 | |||
43 | public function clearFields() |
||
49 | |||
50 | /** |
||
51 | * Gets the fields associated with this statement. |
||
52 | * If no fields are present then defaults to '*'. |
||
53 | * |
||
54 | * @return array fields |
||
55 | */ |
||
56 | public function getFields() |
||
60 | |||
61 | public function build() |
||
77 | } |
||
78 |