| Conditions | 19 |
| Paths | 41 |
| Total Lines | 67 |
| Code Lines | 43 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 35 | public function store(Request $request) |
||
| 36 | { |
||
| 37 | $fbeRequest = new FormbuilderEntryRequest(); |
||
| 38 | $validator = Validator::make($request->all(), $fbeRequest->rules(), $fbeRequest->messages()); |
||
| 39 | |||
| 40 | if ($validator->fails()) { |
||
| 41 | return Redirect::back()->withErrors($validator)->withInput(); |
||
| 42 | } |
||
| 43 | $orginalForm = config('backpack-form.model_form')::where('uniq_id', $request->input('original-form'))->first(); |
||
| 44 | if (empty($orginalForm)) { |
||
| 45 | return Redirect::back()->withErrors(['message' => __('medianet-dev.backpack-form::formbuilder.validations.form_not_found')])->withInput(); |
||
| 46 | } |
||
| 47 | // validate Google ReCaptcha V3 |
||
| 48 | if (!empty(config('backpack-form.captcha_v3_site_key')) && !empty(config('backpack-form.captcha_v3_secret_key')) && !empty($orginalForm->display_captcha) && $request->has('g-recaptcha-response')) { |
||
| 49 | if(!$this->verifyReCaptcha($request->input('g-recaptcha-response'))) { |
||
| 50 | return Redirect::back()->withErrors(['message' => __('medianet-dev.backpack-form::formbuilder.validations.captcha_invalid')])->withInput(); |
||
| 51 | } |
||
| 52 | } |
||
| 53 | // Save entry in database |
||
| 54 | if ($orginalForm->in_database) { |
||
| 55 | |||
| 56 | $error = false; |
||
| 57 | $fieldWithData = []; |
||
| 58 | $fields = json_decode($orginalForm->form); |
||
| 59 | foreach ($fields as $field) { |
||
| 60 | // Escape no input form entry |
||
| 61 | if(isset($field->name)) { |
||
| 62 | $field->userData = [$request->input($field->name)]; |
||
| 63 | $fieldWithData[] = $field; |
||
| 64 | } |
||
| 65 | } |
||
| 66 | if ($error === true) { |
||
| 67 | // @TODO: This redirect it's for custom validation |
||
| 68 | return Redirect::back()->with(['dataError' => json_encode($fieldWithData)])->withInput(); |
||
| 69 | } |
||
| 70 | $newForm = new FormbuilderEntry([ |
||
| 71 | 'structure_form' => $orginalForm->form, |
||
| 72 | 'structure_result' => json_encode($fieldWithData), |
||
| 73 | 'fb_form_id' => $orginalForm->id, |
||
| 74 | ]); |
||
| 75 | $newForm->save(); |
||
| 76 | } |
||
| 77 | $data_admin = []; |
||
| 78 | if ($orginalForm->copy_user) { |
||
| 79 | $data_user = []; |
||
| 80 | $data_user['content_form'] = json_decode($newForm->structure_result); |
||
| 81 | $data_user['form_entry'] = $newForm; |
||
| 82 | $data_user['orginal_form'] = $orginalForm; |
||
| 83 | $mail_to = collect($data_user['content_form'])->where('name', $orginalForm->field_mail_name)->first(); |
||
| 84 | |||
| 85 | if(empty($mail_to) || empty($mail_to->userData[0]) || (!empty($mail_to->userData[0]) && !filter_var($mail_to->userData[0], FILTER_VALIDATE_EMAIL))) { |
||
| 86 | $data_admin['error_mail_user'] = __('medianet-dev.backpack-form::formbuilder.emails.error_mail_user'); |
||
| 87 | } else { |
||
| 88 | Mail::to($mail_to->userData[0])->send(new MailFormBuilderEntry('medianet.backpack-form::emails.user_template', $data_user)); |
||
| 89 | // return (new MailFormBuilderEntry('medianet.backpack-form::emails.user_template', $data_user)); |
||
| 90 | } |
||
| 91 | } |
||
| 92 | if ($orginalForm->by_mail) { |
||
| 93 | $data_admin['content_form'] = json_decode($newForm->structure_result); |
||
| 94 | $data_admin['form_entry'] = $newForm; |
||
| 95 | $data_admin['orginal_form'] = $orginalForm; |
||
| 96 | $mail_to = (!empty($orginalForm->mail_to)) ? array_filter(explode(',', $orginalForm->mail_to)) : config('backpack-form.email.to'); |
||
| 97 | Mail::to($mail_to)->send(new MailFormBuilderEntry('medianet.backpack-form::emails.entry_template', $data_admin)); |
||
| 98 | // return (new MailFormBuilderEntry('medianet.backpack-form::emails.entry_template', $data_admin)); |
||
| 99 | } |
||
| 100 | |||
| 101 | return Redirect::back()->with(['success' => __('medianet-dev.backpack-form::formbuilder.validations.success_db')]); |
||
| 102 | } |
||
| 125 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths