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 |
||
2 | class ODataParams |
||
3 | { |
||
4 | /** |
||
5 | * The ODataFilter or false if not set |
||
6 | * @var false|Data\Filter |
||
7 | */ |
||
8 | public $filter = false; |
||
9 | /** |
||
10 | * An array of properties to expand or false if not set |
||
11 | * @var false|array |
||
12 | */ |
||
13 | public $expand = false; |
||
14 | /** |
||
15 | * An array of properties to display or false if not set |
||
16 | * @var false|array |
||
17 | */ |
||
18 | public $select = false; |
||
19 | /** |
||
20 | * An array of properties to sort by or false if not set |
||
21 | * @var false|array |
||
22 | */ |
||
23 | public $orderby = false; |
||
24 | /** |
||
25 | * The number of results to display or false if not set |
||
26 | * @var false|integer |
||
27 | */ |
||
28 | public $top = false; |
||
29 | /** |
||
30 | * The number of results to skip or false if not set |
||
31 | * @var false|integer |
||
32 | */ |
||
33 | public $skip = false; |
||
34 | /** |
||
35 | * Display the count of results |
||
36 | * @var boolean |
||
37 | */ |
||
38 | public $count = false; |
||
39 | public $search = false; |
||
40 | |||
41 | public function __construct($params) |
||
52 | |||
53 | View Code Duplication | protected function processFilter($params) |
|
64 | |||
65 | protected function processExpand($params) |
||
72 | |||
73 | protected function processSelect($params) |
||
84 | |||
85 | protected function processOrderBy($params) |
||
117 | |||
118 | View Code Duplication | protected function processTop($params) |
|
125 | |||
126 | View Code Duplication | protected function processSkip($params) |
|
133 | |||
134 | protected function processCount($params) |
||
141 | |||
142 | protected function processSearch($params) |
||
149 | } |
||
150 | ?> |
||
151 |
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.