Conditions | 8 |
Paths | 128 |
Total Lines | 64 |
Code Lines | 38 |
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 |
||
125 | public function sendContactForm() |
||
126 | { |
||
127 | $this->onlyPost(); |
||
128 | |||
129 | //verify input values (html special chars ?) |
||
130 | $to = $this->config["admin_email_address"]; |
||
131 | $message = $this->request->getDataFull(); |
||
132 | |||
133 | //Error checking |
||
134 | |||
135 | //check all the fields |
||
136 | $error = false; |
||
137 | $contactErrors = new \stdClass(); |
||
138 | |||
139 | if ($message["contactName"] == "") { |
||
140 | $error = true; |
||
141 | $contactErrors->contactName = "Name must not be empty"; |
||
142 | } |
||
143 | if ($message["contactEmail"] == "") { |
||
144 | $error = true; |
||
145 | $contactErrors->contactEmail = "Email must not be empty"; |
||
146 | } |
||
147 | if ($message["contactSubject"] == "") { |
||
148 | $error = true; |
||
149 | $contactErrors->contactSubject = "Subject must not be empty"; |
||
150 | } |
||
151 | if ($message["contactMessage"] == "") { |
||
152 | $error = true; |
||
153 | $contactErrors->contactMessage = "Message must not be empty"; |
||
154 | } |
||
155 | if (!$this->isEmail($message["contactEmail"])) { |
||
156 | $error = true; |
||
157 | $contactErrors->contactEmail = "email is not valid"; |
||
158 | } |
||
159 | |||
160 | $capchaError = $this->testCapcha($message["g-recaptcha-response"]); |
||
161 | |||
162 | if($capchaError === true) |
||
163 | { |
||
164 | $error = true; |
||
165 | } |
||
166 | |||
167 | //If we found an error, return data to the register form and no create |
||
168 | if ($error) { |
||
169 | $this->session->set("contactInfo", $message); |
||
170 | $this->session->set("contactErrors", $contactErrors); |
||
171 | $this->response->redirect("/home/contact"); |
||
172 | } |
||
173 | |||
174 | $config = $this->siteConfig->getSiteConfig(); |
||
175 | |||
176 | //from here all is good, send mail |
||
177 | $userName = htmlspecialchars($message["contactName"]); |
||
178 | $subject = "Contact from ".$config["site_name"]." : "; |
||
179 | $subject .= htmlspecialchars($message["contactSubject"]); |
||
180 | $textMessage = "<h1>message sent by ".$userName."</h1>"; |
||
181 | $textMessage .= "<p>from : <a href='mailto:".$message["contactEmail"]."'>".$message["contactEmail"]."</a></p>"; |
||
182 | $textMessage .= htmlspecialchars($message["contactMessage"]); |
||
183 | $from = $config["SMTP_from"]; |
||
184 | |||
185 | $this->sendMail->send($to, $subject, $textMessage, $from); |
||
186 | |||
187 | $this->alertBox->setAlert('Email sent'); |
||
188 | $this->response->redirect(); |
||
189 | } |
||
190 | } |