| Conditions | 5 |
| Paths | 36 |
| Total Lines | 53 |
| Lines | 5 |
| Ratio | 9.43 % |
| 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 |
||
| 123 | public function sendActivation($email, $method, $str = '') |
||
| 124 | { |
||
| 125 | try { |
||
| 126 | $user = new User(); |
||
| 127 | |||
| 128 | $activate_model = new AccountActivate(); |
||
| 129 | $user = $user->where('email', $email)->first(); |
||
| 130 | if (!$user) { |
||
| 131 | return redirect()->back()->with('fails', 'Invalid Email'); |
||
| 132 | } |
||
| 133 | |||
| 134 | if ($method == 'GET') { |
||
| 135 | $activate_model = $activate_model->where('email', $email)->first(); |
||
| 136 | $token = $activate_model->token; |
||
| 137 | } else { |
||
| 138 | $token = str_random(40); |
||
| 139 | $activate = $activate_model->create(['email' => $email, 'token' => $token]); |
||
| 140 | $token = $activate->token; |
||
| 141 | } |
||
| 142 | |||
| 143 | $url = url("activate/$token"); |
||
| 144 | //check in the settings |
||
| 145 | $settings = new \App\Model\Common\Setting(); |
||
| 146 | $settings = $settings->where('id', 1)->first(); |
||
| 147 | |||
| 148 | //template |
||
| 149 | $template = new \App\Model\Common\Template(); |
||
| 150 | $temp_id = $settings->where('id', 1)->first()->welcome_mail; |
||
| 151 | $template = $template->where('id', $temp_id)->first(); |
||
| 152 | $from = $settings->email; |
||
| 153 | // var_dump($temp_id); |
||
| 154 | // die(); |
||
| 155 | $to = $user->email; |
||
| 156 | $subject = $template->name; |
||
| 157 | $data = $template->data; |
||
| 158 | $replace = ['name' => $user->first_name.' '.$user->last_name, 'username' => $user->email, 'password' => $str, 'url' => $url]; |
||
| 159 | $type = ''; |
||
| 160 | |||
| 161 | View Code Duplication | if ($template) { |
|
| 162 | $type_id = $template->type; |
||
| 163 | $temp_type = new \App\Model\Common\TemplateType(); |
||
| 164 | $type = $temp_type->where('id', $type_id)->first()->name; |
||
| 165 | } |
||
| 166 | |||
| 167 | //dd($from, $to, $data, $subject, $replace, $type); |
||
| 168 | $templateController = new \App\Http\Controllers\Common\TemplateController(); |
||
| 169 | $mail = $templateController->mailing($from, $to, $data, $subject, $replace, $type); |
||
| 170 | |||
| 171 | return $mail; |
||
| 172 | } catch (\Exception $ex) { |
||
| 173 | throw new \Exception($ex->getMessage()); |
||
| 174 | } |
||
| 175 | } |
||
| 176 | |||
| 193 |
Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a
@returnannotation as described here.