Conditions | 33 |
Paths | 210 |
Total Lines | 198 |
Code Lines | 140 |
Lines | 50 |
Ratio | 25.25 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
60 | public function chartdataHelptopic(Request $request, $date111 = '', $date122 = '', $helptopic = '') |
||
61 | { |
||
62 | $date11 = strtotime($date122); |
||
63 | $date12 = strtotime($date111); |
||
64 | $help_topic = $helptopic; |
||
65 | $duration = $request->input('duration'); |
||
66 | if ($date11 && $date12 && $help_topic) { |
||
67 | $date2 = $date12; |
||
68 | $date1 = $date11; |
||
69 | $duration = null; |
||
70 | if ($request->input('open') == null || $request->input('closed') == null || $request->input('reopened') == null || $request->input('overdue') == null || $request->input('deleted') == null) { |
||
71 | $duration = 'day'; |
||
72 | } |
||
73 | } else { |
||
74 | // generating current date |
||
75 | $date2 = strtotime(date('Y-m-d')); |
||
76 | $date3 = date('Y-m-d'); |
||
77 | $format = 'Y-m-d'; |
||
78 | // generating a date range of 1 month |
||
79 | if ($request->input('duration') == 'day') { |
||
80 | $date1 = strtotime(date($format, strtotime('-15 day'.$date3))); |
||
81 | } elseif ($request->input('duration') == 'week') { |
||
82 | $date1 = strtotime(date($format, strtotime('-69 days'.$date3))); |
||
83 | } elseif ($request->input('duration') == 'month') { |
||
84 | $date1 = strtotime(date($format, strtotime('-179 days'.$date3))); |
||
85 | } else { |
||
86 | $date1 = strtotime(date($format, strtotime('-30 days'.$date3))); |
||
87 | } |
||
88 | // $help_topic = Help_topic::where('status', '=', '1')->min('id'); |
||
89 | } |
||
90 | |||
91 | $return = ''; |
||
92 | $last = ''; |
||
93 | $j = 0; |
||
94 | $created1 = ''; |
||
95 | $closed1 = ''; |
||
96 | $reopened1 = ''; |
||
97 | $in_progress = \DB::table('tickets')->where('help_topic_id', '=', $help_topic)->where('status', '=', 1)->count(); |
||
98 | |||
99 | for ($i = $date1; $i <= $date2; $i = $i + 86400) { |
||
100 | $j++; |
||
101 | $thisDate = date('Y-m-d', $i); |
||
102 | $thisDate1 = date('jS F', $i); |
||
103 | $open_array = []; |
||
104 | $closed_array = []; |
||
105 | $reopened_array = []; |
||
106 | |||
107 | if ($request->input('open') || $request->input('closed') || $request->input('reopened')) { |
||
108 | View Code Duplication | if ($request->input('open') && $request->input('open') == 'on') { |
|
109 | $created = \DB::table('tickets')->select('created_at')->where('help_topic_id', '=', $help_topic)->where('created_at', 'LIKE', '%'.$thisDate.'%')->count(); |
||
110 | $open_array = ['open' => $created]; |
||
111 | } |
||
112 | View Code Duplication | if ($request->input('closed') && $request->input('closed') == 'on') { |
|
113 | $closed = \DB::table('tickets')->select('closed_at')->where('help_topic_id', '=', $help_topic)->where('closed_at', 'LIKE', '%'.$thisDate.'%')->count(); |
||
114 | $closed_array = ['closed' => $closed]; |
||
115 | } |
||
116 | View Code Duplication | if ($request->input('reopened') && $request->input('reopened') == 'on') { |
|
117 | $reopened = \DB::table('tickets')->select('reopened_at')->where('help_topic_id', '=', $help_topic)->where('reopened_at', 'LIKE', '%'.$thisDate.'%')->count(); |
||
118 | $reopened_array = ['reopened' => $reopened]; |
||
119 | } |
||
120 | // if ($request->input('overdue') && $request->input('overdue') == 'on') { |
||
121 | // $overdue = Tickets::where('status', '=', 1)->where('isanswered', '=', 0)->where('dept_id', '=', $dept->id)->orderBy('id', 'DESC')->get(); |
||
122 | // } |
||
123 | // $open_array = ['open'=>$created1]; |
||
124 | // $closed_array = ['closed'=>$closed1]; |
||
125 | // $reopened_array = ['reopened'=>$reopened1]; |
||
126 | $value = ['date' => $thisDate1]; |
||
127 | // if($open_array) { |
||
128 | $value = array_merge($value, $open_array); |
||
129 | $value = array_merge($value, $closed_array); |
||
130 | $value = array_merge($value, $reopened_array); |
||
131 | $value = array_merge($value, ['inprogress' => $in_progress]); |
||
132 | // } else { |
||
133 | // $value = ""; |
||
134 | // } |
||
135 | $array = array_map('htmlentities', $value); |
||
136 | $json = html_entity_decode(json_encode($array)); |
||
137 | $return .= $json.','; |
||
138 | } else { |
||
139 | if ($duration == 'week') { |
||
140 | $created = \DB::table('tickets')->select('created_at')->where('help_topic_id', '=', $help_topic)->where('created_at', 'LIKE', '%'.$thisDate.'%')->count(); |
||
141 | $created1 += $created; |
||
142 | $closed = \DB::table('tickets')->select('closed_at')->where('help_topic_id', '=', $help_topic)->where('closed_at', 'LIKE', '%'.$thisDate.'%')->count(); |
||
143 | $closed1 += $closed; |
||
144 | $reopened = \DB::table('tickets')->select('reopened_at')->where('help_topic_id', '=', $help_topic)->where('reopened_at', 'LIKE', '%'.$thisDate.'%')->count(); |
||
145 | $reopened1 += $reopened; |
||
146 | View Code Duplication | if ($j % 7 == 0) { |
|
147 | $open_array = ['open' => $created1]; |
||
148 | $created1 = 0; |
||
149 | $closed_array = ['closed' => $closed1]; |
||
150 | $closed1 = 0; |
||
151 | $reopened_array = ['reopened' => $reopened1]; |
||
152 | $reopened1 = 0; |
||
153 | $value = ['date' => $thisDate1]; |
||
154 | // if($open_array) { |
||
155 | $value = array_merge($value, $open_array); |
||
156 | $value = array_merge($value, $closed_array); |
||
157 | $value = array_merge($value, $reopened_array); |
||
158 | $value = array_merge($value, ['inprogress' => $in_progress]); |
||
159 | // } else { |
||
160 | // $value = ""; |
||
161 | // } |
||
162 | $array = array_map('htmlentities', $value); |
||
163 | $json = html_entity_decode(json_encode($array)); |
||
164 | $return .= $json.','; |
||
165 | } |
||
166 | } elseif ($duration == 'month') { |
||
167 | $created_month = \DB::table('tickets')->select('created_at')->where('help_topic_id', '=', $help_topic)->where('created_at', 'LIKE', '%'.$thisDate.'%')->count(); |
||
168 | $created1 += $created_month; |
||
169 | $closed_month = \DB::table('tickets')->select('closed_at')->where('help_topic_id', '=', $help_topic)->where('closed_at', 'LIKE', '%'.$thisDate.'%')->count(); |
||
170 | $closed1 += $closed_month; |
||
171 | $reopened_month = \DB::table('tickets')->select('reopened_at')->where('help_topic_id', '=', $help_topic)->where('reopened_at', 'LIKE', '%'.$thisDate.'%')->count(); |
||
172 | $reopened1 += $reopened_month; |
||
173 | View Code Duplication | if ($j % 30 == 0) { |
|
174 | $open_array = ['open' => $created1]; |
||
175 | $created1 = 0; |
||
176 | $closed_array = ['closed' => $closed1]; |
||
177 | $closed1 = 0; |
||
178 | $reopened_array = ['reopened' => $reopened1]; |
||
179 | $reopened1 = 0; |
||
180 | $value = ['date' => $thisDate1]; |
||
181 | |||
182 | $value = array_merge($value, $open_array); |
||
183 | $value = array_merge($value, $closed_array); |
||
184 | $value = array_merge($value, $reopened_array); |
||
185 | $value = array_merge($value, ['inprogress' => $in_progress]); |
||
186 | |||
187 | $array = array_map('htmlentities', $value); |
||
188 | $json = html_entity_decode(json_encode($array)); |
||
189 | $return .= $json.','; |
||
190 | } |
||
191 | } else { |
||
192 | if ($request->input('default') == null) { |
||
193 | $help_topic = Help_topic::where('status', '=', '1')->min('id'); |
||
194 | } |
||
195 | $created = \DB::table('tickets')->select('created_at')->where('help_topic_id', '=', $help_topic)->where('created_at', 'LIKE', '%'.$thisDate.'%')->count(); |
||
196 | $open_array = ['open' => $created]; |
||
197 | $closed = \DB::table('tickets')->select('closed_at')->where('help_topic_id', '=', $help_topic)->where('closed_at', 'LIKE', '%'.$thisDate.'%')->count(); |
||
198 | $closed_array = ['closed' => $closed]; |
||
199 | $reopened = \DB::table('tickets')->select('reopened_at')->where('help_topic_id', '=', $help_topic)->where('reopened_at', 'LIKE', '%'.$thisDate.'%')->count(); |
||
200 | $reopened_array = ['reopened' => $reopened]; |
||
201 | if ($j % 1 == 0) { |
||
202 | $open_array = ['open' => $created]; |
||
203 | $created = 0; |
||
204 | $closed_array = ['closed' => $closed]; |
||
205 | $closed = 0; |
||
206 | $reopened_array = ['reopened' => $reopened]; |
||
207 | $reopened = 0; |
||
208 | $value = ['date' => $thisDate1]; |
||
209 | if ($request->input('default') == null) { |
||
210 | $value = array_merge($value, $open_array); |
||
211 | $value = array_merge($value, $closed_array); |
||
212 | $value = array_merge($value, $reopened_array); |
||
213 | $value = array_merge($value, ['inprogress' => $in_progress]); |
||
214 | } else { |
||
215 | if ($duration == null) { |
||
216 | if ($request->input('open') == 'on') { |
||
217 | $value = array_merge($value, $open_array); |
||
218 | } |
||
219 | if ($request->input('closed') == 'on') { |
||
220 | $value = array_merge($value, $closed_array); |
||
221 | } |
||
222 | if ($request->input('reopened') == 'on') { |
||
223 | $value = array_merge($value, $reopened_array); |
||
224 | } |
||
225 | } else { |
||
226 | $value = array_merge($value, $open_array); |
||
227 | $value = array_merge($value, $closed_array); |
||
228 | $value = array_merge($value, $reopened_array); |
||
229 | $value = array_merge($value, ['inprogress' => $in_progress]); |
||
230 | } |
||
231 | } |
||
232 | |||
233 | // } else { |
||
234 | // $value = ""; |
||
235 | // } |
||
236 | $array = array_map('htmlentities', $value); |
||
237 | $json = html_entity_decode(json_encode($array)); |
||
238 | $return .= $json.','; |
||
239 | } |
||
240 | } |
||
241 | } |
||
242 | |||
243 | // $value = ['date' => $thisDate]; |
||
244 | // if($open_array) { |
||
245 | // $value = array_merge($value,$open_array); |
||
246 | // } |
||
247 | // if($closed_array) { |
||
248 | // $value = array_merge($value,$closed_array); |
||
249 | // } |
||
250 | // if($reopened_array) { |
||
251 | // $value = array_merge($value,$reopened_array); |
||
252 | // } |
||
253 | } |
||
254 | $last = rtrim($return, ','); |
||
255 | |||
256 | return '['.$last.']'; |
||
257 | } |
||
258 | |||
269 |
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.