These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
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) |
||
42 | { |
||
43 | View Code Duplication | if(isset($params['filter'])) |
|
0 ignored issues
–
show
|
|||
44 | { |
||
45 | $this->filter = new \Data\Filter($params['filter']); |
||
46 | } |
||
47 | else if(isset($params['$filter'])) |
||
48 | { |
||
49 | $this->filter = new \Data\Filter($params['$filter']); |
||
50 | } |
||
51 | |||
52 | if(isset($params['$expand'])) |
||
53 | { |
||
54 | $this->expand = explode(',',$params['$expand']); |
||
55 | } |
||
56 | |||
57 | if(isset($params['select'])) |
||
58 | { |
||
59 | $this->select = explode(',',$params['select']); |
||
60 | } |
||
61 | else if(isset($params['$select'])) |
||
62 | { |
||
63 | $this->select = explode(',',$params['$select']); |
||
64 | } |
||
65 | |||
66 | if(isset($params['$orderby'])) |
||
67 | { |
||
68 | $this->orderby = array(); |
||
69 | $orderby = explode(',',$params['$orderby']); |
||
70 | $count = count($orderby); |
||
71 | for($i = 0; $i < $count; $i++) |
||
72 | { |
||
73 | $exp = explode(' ',$orderby[$i]); |
||
74 | if(count($exp) === 1) |
||
75 | { |
||
76 | //Default to assending |
||
77 | $this->orderby[$exp[0]] = 1; |
||
78 | } |
||
79 | else |
||
80 | { |
||
81 | switch($exp[1]) |
||
82 | { |
||
83 | case 'asc': |
||
84 | $this->orderby[$exp[0]] = 1; |
||
85 | break; |
||
86 | case 'desc': |
||
87 | $this->orderby[$exp[0]] = -1; |
||
88 | break; |
||
89 | default: |
||
90 | throw new Exception('Unknown orderby operation'); |
||
91 | } |
||
92 | } |
||
93 | } |
||
94 | } |
||
95 | |||
96 | if(isset($params['$top'])) |
||
97 | { |
||
98 | $this->top = $params['$top']; |
||
99 | } |
||
100 | |||
101 | if(isset($params['$skip'])) |
||
102 | { |
||
103 | $this->skip = $params['$skip']; |
||
104 | } |
||
105 | |||
106 | if(isset($params['$count']) && $params['$count'] === 'true') |
||
107 | { |
||
108 | $this->count = true; |
||
109 | } |
||
110 | |||
111 | if(isset($params['$seach'])) |
||
112 | { |
||
113 | throw new Exception('Search not yet implemented'); |
||
114 | } |
||
115 | } |
||
116 | } |
||
117 | ?> |
||
118 |
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.