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 |
||
72 | public function sendContactForm() |
||
73 | { |
||
74 | $this->onlyPost(); |
||
75 | |||
76 | //verify input values (html special chars ?) |
||
77 | $to = $this->config["admin_email_address"]; |
||
78 | $message = $this->request->getDataFull(); |
||
79 | |||
80 | //Error checking |
||
81 | |||
82 | //check all the fields |
||
83 | $error = false; |
||
84 | $contactErrors = new \stdClass(); |
||
85 | |||
86 | if ($message["contactName"] == "") { |
||
87 | $error = true; |
||
88 | $contactErrors->contactName = "Name must not be empty"; |
||
89 | } |
||
90 | if ($message["contactEmail"] == "") { |
||
91 | $error = true; |
||
92 | $contactErrors->contactEmail = "Email must not be empty"; |
||
93 | } |
||
94 | if ($message["contactSubject"] == "") { |
||
95 | $error = true; |
||
96 | $contactErrors->contactSubject = "Subject must not be empty"; |
||
97 | } |
||
98 | if ($message["contactMessage"] == "") { |
||
99 | $error = true; |
||
100 | $contactErrors->contactMessage = "Message must not be empty"; |
||
101 | } |
||
102 | if (!$this->isEmail($message["contactEmail"])) { |
||
103 | $error = true; |
||
104 | $contactErrors->contactEmail = "email is not valid"; |
||
105 | } |
||
106 | |||
107 | //If we found an error, return data to the register form and no create |
||
108 | if ($error) { |
||
109 | $this->session->set("contactInfo", $message); |
||
110 | $this->session->set("contactErrors", $contactErrors); |
||
111 | $this->response->redirect(); |
||
112 | } |
||
113 | |||
114 | $config = $this->siteConfig->getSiteConfig(); |
||
115 | |||
116 | //from here all is good, send mail |
||
117 | $userName = htmlspecialchars($message["contactName"]); |
||
118 | $subject = "Contact from ".$config["site_name"]." : "; |
||
119 | $subject .= htmlspecialchars($message["contactSubject"]); |
||
120 | $textMessage = "<h1>message sent by ".$userName."</h1>"; |
||
121 | $textMessage .= htmlspecialchars($message["contactMessage"]); |
||
122 | $from = $message["contactEmail"]; |
||
123 | |||
124 | $this->sendMail->send($to, $subject, $textMessage, $from); |
||
125 | |||
126 | $this->alertBox->setAlert('Email sent'); |
||
127 | $this->response->redirect(); |
||
128 | } |
||
129 | } |