| Conditions | 10 |
| Paths | 6 |
| Total Lines | 42 |
| Code Lines | 26 |
| 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 |
||
| 58 | public function actionSignup() |
||
| 59 | { |
||
| 60 | try { |
||
| 61 | $socialAuth = \Yii::$container->get(SocialAuth::class, [Yii::$app->session['authClient']]); |
||
| 62 | } catch (\Throwable $e) { |
||
| 63 | Yii::error($e); |
||
| 64 | return $this->redirect(['/']); |
||
| 65 | } |
||
| 66 | |||
| 67 | $user = $socialAuth->prepareUser(); |
||
| 68 | if ($user === null) { |
||
| 69 | return $this->redirect(['/']); |
||
| 70 | } |
||
| 71 | |||
| 72 | $model = new SignupProviderForm($user); |
||
| 73 | |||
| 74 | if (!$user->isNewRecord && $user->isActive() === false) { |
||
| 75 | Yii::$app->session->setFlash('error', $user->getStatusDescription()); |
||
| 76 | return $this->redirect(['/']); |
||
| 77 | } |
||
| 78 | |||
| 79 | if (!$user->isNewRecord && $user->isActive()) { |
||
| 80 | $model->login(); |
||
| 81 | return $this->redirect(['/']); |
||
| 82 | } |
||
| 83 | |||
| 84 | if ($model->validate() || ($model->load(Yii::$app->request->post()) && $model->validate())) { |
||
| 85 | $model->signup(); |
||
| 86 | $model->sendEmail(); |
||
| 87 | |||
| 88 | Yii::$app->session->setFlash( |
||
| 89 | 'success', |
||
| 90 | Yii::t('app.msg', 'Please activate your account') . '. ' . |
||
| 91 | Yii::t('app.msg', 'A letter for activation was sent to {email}', ['email' => $model->email]) |
||
| 92 | ); |
||
| 93 | return $this->redirect(['/']); |
||
| 94 | } |
||
| 95 | |||
| 96 | return $this->render('signup', [ |
||
| 97 | 'model' => $model |
||
| 98 | ]); |
||
| 99 | } |
||
| 100 | } |
||
| 101 |