Conditions | 7 |
Paths | 64 |
Total Lines | 56 |
Code Lines | 34 |
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 |
||
96 | public function sendContactForm() |
||
97 | { |
||
98 | $this->onlyPost(); |
||
99 | |||
100 | //verify input values (html special chars ?) |
||
101 | $to = $this->config["admin_email_address"]; |
||
102 | $message = $this->request->getDataFull(); |
||
103 | |||
104 | //Error checking |
||
105 | |||
106 | //check all the fields |
||
107 | $error = false; |
||
108 | $contactErrors = new \stdClass(); |
||
109 | |||
110 | if ($message["contactName"] == "") { |
||
111 | $error = true; |
||
112 | $contactErrors->contactName = "Name must not be empty"; |
||
113 | } |
||
114 | if ($message["contactEmail"] == "") { |
||
115 | $error = true; |
||
116 | $contactErrors->contactEmail = "Email must not be empty"; |
||
117 | } |
||
118 | if ($message["contactSubject"] == "") { |
||
119 | $error = true; |
||
120 | $contactErrors->contactSubject = "Subject must not be empty"; |
||
121 | } |
||
122 | if ($message["contactMessage"] == "") { |
||
123 | $error = true; |
||
124 | $contactErrors->contactMessage = "Message must not be empty"; |
||
125 | } |
||
126 | if (!$this->isEmail($message["contactEmail"])) { |
||
127 | $error = true; |
||
128 | $contactErrors->contactEmail = "email is not valid"; |
||
129 | } |
||
130 | |||
131 | //If we found an error, return data to the register form and no create |
||
132 | if ($error) { |
||
133 | $this->session->set("contactInfo", $message); |
||
134 | $this->session->set("contactErrors", $contactErrors); |
||
135 | $this->response->redirect("/home/contact"); |
||
136 | } |
||
137 | |||
138 | $config = $this->siteConfig->getSiteConfig(); |
||
139 | |||
140 | //from here all is good, send mail |
||
141 | $userName = htmlspecialchars($message["contactName"]); |
||
142 | $subject = "Contact from ".$config["site_name"]." : "; |
||
143 | $subject .= htmlspecialchars($message["contactSubject"]); |
||
144 | $textMessage = "<h1>message sent by ".$userName."</h1>"; |
||
145 | $textMessage .= htmlspecialchars($message["contactMessage"]); |
||
146 | $from = $message["contactEmail"]; |
||
147 | |||
148 | $this->sendMail->send($to, $subject, $textMessage, $from); |
||
149 | |||
150 | $this->alertBox->setAlert('Email sent'); |
||
151 | $this->response->redirect(); |
||
152 | } |
||
153 | } |