| Conditions | 20 |
| Paths | 4035 |
| Total Lines | 105 |
| Code Lines | 80 |
| Lines | 0 |
| Ratio | 0 % |
| 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 |
||
| 145 | public function postedForm(User $user, ClientRequest $request, Ticket $ticket_settings, Ticket_source $ticket_source, Ticket_attachments $ta, CountryCode $code) { |
||
| 146 | try { |
||
| 147 | $form_extras = $request->except('Name', 'Phone', 'Email', 'Subject', 'Details', 'helptopic', '_wysihtml5_mode', '_token', 'mobile', 'Code', 'priority', 'attachment'); |
||
| 148 | $name = $request->input('Name'); |
||
| 149 | $phone = $request->input('Phone'); |
||
| 150 | if ($request->input('Email')) { |
||
| 151 | if ($request->input('Email')) { |
||
| 152 | $email = $request->input('Email'); |
||
| 153 | } else { |
||
| 154 | $email = null; |
||
| 155 | } |
||
| 156 | } else { |
||
| 157 | $email = null; |
||
| 158 | } |
||
| 159 | $subject = $request->input('Subject'); |
||
| 160 | $details = $request->input('Details'); |
||
| 161 | $phonecode = $request->input('Code'); |
||
| 162 | if ($request->input('mobile')) { |
||
| 163 | $mobile_number = $request->input('mobile'); |
||
| 164 | } else { |
||
| 165 | $mobile_number = null; |
||
| 166 | } |
||
| 167 | $status = $ticket_settings->first()->status; |
||
| 168 | $helptopic = $request->input('helptopic'); |
||
| 169 | $helpTopicObj = Help_topic::where('id', '=', $helptopic); |
||
| 170 | if ($helpTopicObj->exists() && ($helpTopicObj->value('status') == 1)) { |
||
| 171 | $department = $helpTopicObj->value('department'); |
||
| 172 | } else { |
||
| 173 | $defaultHelpTopicID = Ticket::where('id', '=', '1')->first()->help_topic; |
||
| 174 | $department = Help_topic::where('id', '=', $defaultHelpTopicID)->value('department'); |
||
| 175 | } |
||
| 176 | $sla = $ticket_settings->first()->sla; |
||
| 177 | |||
| 178 | // $priority = $ticket_settings->first()->priority; |
||
| 179 | $default_priority = Ticket_Priority::where('is_default', '=', 1)->first(); |
||
| 180 | $user_priority = CommonSettings::where('option_name', '=', 'user_priority')->first(); |
||
| 181 | if (!($request->input('priority'))) { |
||
| 182 | $priority = $default_priority->priority_id; |
||
| 183 | if ($helpTopicObj->exists() && ($helpTopicObj->value('status') == 1)) { |
||
| 184 | $priority = $helpTopicObj->value('priority'); |
||
| 185 | } |
||
| 186 | } else { |
||
| 187 | $priority = $request->input('priority'); |
||
| 188 | } |
||
| 189 | $source = $ticket_source->where('name', '=', 'web')->first()->id; |
||
| 190 | $attachments = $request->file('attachment'); |
||
| 191 | $collaborator = null; |
||
| 192 | $assignto = null; |
||
| 193 | if ($helpTopicObj->exists() && ($helpTopicObj->value('status') == 1)) { |
||
| 194 | $assignto = $helpTopicObj->value('auto_assign'); |
||
| 195 | } |
||
| 196 | $auto_response = 0; |
||
| 197 | $team_assign = null; |
||
| 198 | if ($phone != null || $mobile_number != null) { |
||
| 199 | $location = GeoIP::getLocation(); |
||
| 200 | $geoipcode = $code->where('iso', '=', $location->iso_code)->first(); |
||
| 201 | if ($phonecode == null) { |
||
| 202 | $data = [ |
||
| 203 | 'fails' => Lang::get('lang.country-code-required-error'), |
||
| 204 | 'phonecode' => $geoipcode->phonecode, |
||
| 205 | 'country_code_error' => 1, |
||
| 206 | ]; |
||
| 207 | |||
| 208 | return Redirect::back()->with($data)->withInput($request->except('password')); |
||
| 209 | } else { |
||
| 210 | $code = CountryCode::select('phonecode')->where('phonecode', '=', $phonecode)->get(); |
||
| 211 | if (!count($code)) { |
||
| 212 | $data = [ |
||
| 213 | 'fails' => Lang::get('lang.incorrect-country-code-error'), |
||
| 214 | 'phonecode' => $geoipcode->phonecode, |
||
| 215 | 'country_code_error' => 1, |
||
| 216 | ]; |
||
| 217 | |||
| 218 | return Redirect::back()->with($data)->withInput($request->except('password')); |
||
| 219 | } |
||
| 220 | } |
||
| 221 | } |
||
| 222 | \Event::fire(new \App\Events\ClientTicketFormPost($form_extras, $email, $source)); |
||
| 223 | $result = $this->TicketWorkflowController->workflow($email, $name, $subject, $details, $phone, $phonecode, $mobile_number, $helptopic, $sla, $priority, $source, $collaborator, $department, $assignto, $team_assign, $status, $form_extras, $auto_response); |
||
| 224 | // dd($result); |
||
| 225 | if ($result[1] == 1) { |
||
| 226 | $ticketId = Tickets::where('ticket_number', '=', $result[0])->first(); |
||
| 227 | $thread = Ticket_Thread::where('ticket_id', '=', $ticketId->id)->first(); |
||
| 228 | if ($attachments != null) { |
||
| 229 | foreach ($attachments as $attachment) { |
||
| 230 | if ($attachment != null) { |
||
| 231 | $name = $attachment->getClientOriginalName(); |
||
| 232 | $type = $attachment->getClientOriginalExtension(); |
||
| 233 | $size = $attachment->getSize(); |
||
| 234 | $data = file_get_contents($attachment->getRealPath()); |
||
| 235 | $attachPath = $attachment->getRealPath(); |
||
| 236 | $ta->create(['thread_id' => $thread->id, 'name' => $name, 'size' => $size, 'type' => $type, 'file' => $data, 'poster' => 'ATTACHMENT']); |
||
| 237 | } |
||
| 238 | } |
||
| 239 | } |
||
| 240 | // dd($result); |
||
| 241 | return Redirect::back()->with('success', Lang::get('lang.Ticket-has-been-created-successfully-your-ticket-number-is') . ' ' . $result[0] . '. ' . Lang::get('lang.Please-save-this-for-future-reference')); |
||
| 242 | } else { |
||
| 243 | return Redirect::back()->withInput($request->except('password'))->with('fails', Lang::get('lang.failed-to-create-user-tcket-as-mobile-has-been-taken')); |
||
| 244 | } |
||
| 245 | } catch (\Exception $ex) { |
||
| 246 | return redirect()->back()->with('fails', $ex->getMessage()); |
||
| 247 | } |
||
| 248 | // dd($result); |
||
| 249 | } |
||
| 250 | |||
| 318 |
Adding a
@returnannotation 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.