| Conditions | 11 |
| Paths | 2 |
| Total Lines | 102 |
| Code Lines | 54 |
| 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 |
||
| 78 | public function init() |
||
| 79 | { |
||
| 80 | parent::init(); |
||
| 81 | self::$plugin = $this; |
||
| 82 | |||
| 83 | if (!Craft::$app->plugins->isPluginInstalled('contact-form') && !Craft::$app->request->getIsConsoleRequest()) { |
||
| 84 | Craft::$app->session->setNotice(Craft::t('contact-form-extensions', 'The Contact Form plugin is not installed or activated, Contact Form Extensions does not work without it.')); |
||
| 85 | } |
||
| 86 | |||
| 87 | Event::on(View::class, View::EVENT_BEFORE_RENDER_TEMPLATE, function (TemplateEvent $e) { |
||
| 88 | if ( |
||
| 89 | $e->template === 'settings/plugins/_settings' && |
||
| 90 | $e->variables['plugin'] === $this |
||
| 91 | ) { |
||
| 92 | // Add the tabs |
||
| 93 | $e->variables['tabs'] = [ |
||
| 94 | ['label' => 'Settings', 'url' => '#settings-tab-settings'], |
||
| 95 | ['label' => 'reCAPTCHA', 'url' => '#settings-tab-recaptcha'], |
||
| 96 | ]; |
||
| 97 | } |
||
| 98 | }); |
||
| 99 | |||
| 100 | Event::on(UrlManager::class, UrlManager::EVENT_REGISTER_CP_URL_RULES, function (RegisterUrlRulesEvent $event) { |
||
| 101 | $event->rules = array_merge($event->rules, [ |
||
| 102 | 'contact-form-extensions/submissions/<submissionId:\d+>' => 'contact-form-extensions/submissions/show-submission', |
||
| 103 | 'contact-form-extensions/submissions/<submissionId:\d+>/<siteHandle:{handle}>' => 'contact-form-extensions/submissions/show-submission', |
||
| 104 | ]); |
||
| 105 | }); |
||
| 106 | |||
| 107 | Event::on(Mailer::class, Mailer::EVENT_BEFORE_SEND, function (SendEvent $e) { |
||
| 108 | if ($e->isSpam) { |
||
| 109 | return; |
||
| 110 | } |
||
| 111 | |||
| 112 | if ($this->settings->recaptcha) { |
||
| 113 | $recaptcha = $this->contactFormExtensionsService->recaptcha; |
||
| 114 | $captchaResponse = Craft::$app->request->getParam('g-recaptcha-response'); |
||
| 115 | |||
| 116 | if (!$recaptcha->verifyResponse($captchaResponse, $_SERVER['REMOTE_ADDR'])) { |
||
| 117 | $e->isSpam = true; |
||
| 118 | $e->handled = true; |
||
| 119 | |||
| 120 | return; |
||
| 121 | } |
||
| 122 | } |
||
| 123 | |||
| 124 | $submission = $e->submission; |
||
| 125 | if ($this->settings->enableDatabase) { |
||
| 126 | $this->contactFormExtensionsService->saveSubmission($submission); |
||
| 127 | } |
||
| 128 | |||
| 129 | if ($this->settings->enableTemplateOverwrite) { |
||
| 130 | // First set the template mode to the Site templates |
||
| 131 | Craft::$app->view->setTemplateMode(View::TEMPLATE_MODE_SITE); |
||
| 132 | |||
| 133 | // Render the set template |
||
| 134 | $html = Craft::$app->view->renderTemplate( |
||
| 135 | $this->settings->notificationTemplate, |
||
| 136 | ['submission' => $e->submission] |
||
| 137 | ); |
||
| 138 | |||
| 139 | // Update the message body |
||
| 140 | $e->message->setHtmlBody($html); |
||
| 141 | |||
| 142 | // Set the template mode back to Control Panel |
||
| 143 | Craft::$app->view->setTemplateMode(View::TEMPLATE_MODE_CP); |
||
| 144 | } |
||
| 145 | }); |
||
| 146 | |||
| 147 | Event::on(Mailer::class, Mailer::EVENT_AFTER_SEND, function (SendEvent $e) { |
||
| 148 | if ($this->settings->enableConfirmationEmail) { |
||
| 149 | // First set the template mode to the Site templates |
||
| 150 | Craft::$app->view->setTemplateMode(View::TEMPLATE_MODE_SITE); |
||
| 151 | |||
| 152 | // Render the set template |
||
| 153 | $html = Craft::$app->view->renderTemplate( |
||
| 154 | $this->settings->confirmationTemplate, |
||
| 155 | ['submission' => $e->submission] |
||
| 156 | ); |
||
| 157 | |||
| 158 | // Create the confirmation email |
||
| 159 | $message = new Message(); |
||
| 160 | $message->setTo($e->submission->fromEmail); |
||
| 161 | $message->setFrom($e->message->getTo()); |
||
| 162 | $message->setHtmlBody($html); |
||
| 163 | $message->setSubject($this->settings->getConfirmationSubject()); |
||
| 164 | |||
| 165 | // Send the mail |
||
| 166 | Craft::$app->mailer->send($message); |
||
| 167 | |||
| 168 | // Set the template mode back to Control Panel |
||
| 169 | Craft::$app->view->setTemplateMode(View::TEMPLATE_MODE_CP); |
||
| 170 | } |
||
| 171 | }); |
||
| 172 | |||
| 173 | Event::on( |
||
| 174 | CraftVariable::class, |
||
| 175 | CraftVariable::EVENT_INIT, |
||
| 176 | function (Event $event) { |
||
| 177 | /** @var CraftVariable $variable */ |
||
| 178 | $variable = $event->sender; |
||
| 179 | $variable->set('contactFormExtensions', ContactFormExtensionsVariable::class); |
||
| 180 | } |
||
| 240 |
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