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 | $this->processFilter($params); |
||
44 | $this->processExpand($params); |
||
45 | $this->processSelect($params); |
||
46 | $this->processOrderBy($params); |
||
47 | $this->processTop($params); |
||
48 | $this->processSkip($params); |
||
49 | $this->processCount($params); |
||
50 | $this->processSearch($params); |
||
51 | } |
||
52 | |||
53 | protected function processFilter($params) |
||
0 ignored issues
–
show
|
|||
54 | { |
||
55 | if(isset($params['filter'])) |
||
56 | { |
||
57 | $this->filter = new \Data\Filter($params['filter']); |
||
58 | } |
||
59 | else if(isset($params['$filter'])) |
||
60 | { |
||
61 | $this->filter = new \Data\Filter($params['$filter']); |
||
62 | } |
||
63 | } |
||
64 | |||
65 | protected function processExpand($params) |
||
66 | { |
||
67 | if(isset($params['$expand'])) |
||
68 | { |
||
69 | $this->expand = explode(',', $params['$expand']); |
||
70 | } |
||
71 | } |
||
72 | |||
73 | protected function processSelect($params) |
||
74 | { |
||
75 | if(isset($params['select'])) |
||
76 | { |
||
77 | $this->select = explode(',', $params['select']); |
||
78 | } |
||
79 | else if(isset($params['$select'])) |
||
80 | { |
||
81 | $this->select = explode(',', $params['$select']); |
||
82 | } |
||
83 | } |
||
84 | |||
85 | protected function processOrderBy($params) |
||
86 | { |
||
87 | if(isset($params['$orderby'])) |
||
88 | { |
||
89 | $this->orderby = array(); |
||
90 | $orderby = explode(',', $params['$orderby']); |
||
91 | $count = count($orderby); |
||
92 | for($i = 0; $i < $count; $i++) |
||
93 | { |
||
94 | $exp = explode(' ', $orderby[$i]); |
||
95 | if(count($exp) === 1) |
||
96 | { |
||
97 | //Default to assending |
||
98 | $this->orderby[$exp[0]] = 1; |
||
99 | } |
||
100 | else |
||
101 | { |
||
102 | switch($exp[1]) |
||
103 | { |
||
104 | case 'asc': |
||
105 | $this->orderby[$exp[0]] = 1; |
||
106 | break; |
||
107 | case 'desc': |
||
108 | $this->orderby[$exp[0]] = -1; |
||
109 | break; |
||
110 | default: |
||
111 | throw new Exception('Unknown orderby operation'); |
||
112 | } |
||
113 | } |
||
114 | } |
||
115 | } |
||
116 | } |
||
117 | |||
118 | protected function processTop($params) |
||
0 ignored issues
–
show
This method seems to be duplicated in your project.
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. ![]() |
|||
119 | { |
||
120 | if(isset($params['$top']) && is_numeric($params['$top'])) |
||
121 | { |
||
122 | $this->top = intval($params['$top']); |
||
123 | } |
||
124 | } |
||
125 | |||
126 | protected function processSkip($params) |
||
0 ignored issues
–
show
This method seems to be duplicated in your project.
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. ![]() |
|||
127 | { |
||
128 | if(isset($params['$skip']) && is_numeric($params['$skip'])) |
||
129 | { |
||
130 | $this->skip = intval($params['$skip']); |
||
131 | } |
||
132 | } |
||
133 | |||
134 | protected function processCount($params) |
||
135 | { |
||
136 | if(isset($params['$count']) && strcasecmp($params['$count'], 'true') === 0) |
||
137 | { |
||
138 | $this->count = true; |
||
139 | } |
||
140 | } |
||
141 | |||
142 | protected function processSearch($params) |
||
143 | { |
||
144 | if(isset($params['$search'])) |
||
145 | { |
||
146 | throw new Exception('Search not yet implemented'); |
||
147 | } |
||
148 | } |
||
149 | } |
||
150 | ?> |
||
0 ignored issues
–
show
It is not recommended to use PHP's closing tag
?> in files other than templates.
Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore. A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever. ![]() |
|||
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.