Conditions | 10 |
Paths | 34 |
Total Lines | 40 |
Code Lines | 23 |
Lines | 0 |
Ratio | 0 % |
Changes | 4 | ||
Bugs | 0 | Features | 2 |
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 |
||
84 | public function actionEdit($id = null) |
||
85 | { |
||
86 | $model = new UserForm(); |
||
87 | |||
88 | if ($id) { |
||
89 | $model = $this->loadModel($model, $id); |
||
90 | } |
||
91 | |||
92 | if (Yii::$app->request->isPost) { |
||
93 | if ($model->isNewRecord) { |
||
94 | $model->setConfirmed(); |
||
95 | } |
||
96 | |||
97 | if ($model->load(Yii::$app->request->post()) && $model->save()) { |
||
98 | $auth = Yii::$app->authManager; |
||
99 | $auth->revokeAll($model->id); |
||
100 | |||
101 | if (!empty($model->role)) { |
||
102 | $role = $auth->getRole($model->role); |
||
103 | if ($role) { |
||
104 | $auth->assign($role, $model->id); |
||
105 | } |
||
106 | } |
||
107 | |||
108 | Yii::$app->session->setFlash('success', Yii::t('app', 'Saved successfully')); |
||
109 | if (Yii::$app->request->isAjax) { |
||
110 | return $this->response(['redirect' => Url::toRoute(['edit', 'id' => $model->id])]); |
||
111 | } |
||
112 | } else { |
||
113 | if (Yii::$app->request->isAjax) { |
||
114 | return $this->response(Util::collectModelErrors($model)); |
||
115 | } |
||
116 | } |
||
117 | } |
||
118 | |||
119 | return $this->render('edit', [ |
||
120 | 'model' => $model, |
||
121 | 'roles' => Yii::$app->authManager->getRoles() |
||
122 | ]); |
||
123 | } |
||
124 | |||
167 |