Conditions | 11 |
Paths | 7 |
Total Lines | 70 |
Code Lines | 42 |
Lines | 3 |
Ratio | 4.29 % |
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 |
||
129 | |||
130 | // check if form is submited and validation is passed |
||
131 | View Code Duplication | if ($model->send() && $model->validate()) { |
|
|
|||
132 | $model->make(); |
||
133 | App::$Event->run(static::EVENT_CHANGE_PASSWORD, [ |
||
134 | 'model' => $model |
||
135 | ]); |
||
136 | |||
137 | App::$Session->getFlashBag()->add('success', __('Password is successful changed')); |
||
138 | } |
||
139 | |||
140 | // set response output |
||
141 | return $this->view->render('password', [ |
||
142 | 'model' => $model |
||
143 | ]); |
||
144 | } |
||
145 | |||
146 | /** |
||
147 | * Show user logs |
||
148 | * @return string |
||
149 | * @throws \Ffcms\Core\Exception\SyntaxException |
||
150 | * @throws ForbiddenException |
||
151 | */ |
||
152 | public function actionLog() |
||
153 | { |
||
154 | // check if user is authorized |
||
155 | if (!App::$User->isAuth()) { |
||
156 | throw new ForbiddenException(); |
||
157 | } |
||
158 | |||
159 | // get log records |
||
160 | $records = UserLog::where('user_id', App::$User->identity()->getId()); |
||
161 | if ($records->count() > 0) { |
||
162 | $records = $records->orderBy('id', 'DESC'); |
||
163 | } |
||
164 | |||
165 | // render output view |
||
166 | return $this->view->render('log', [ |
||
167 | 'records' => $records |
||
168 | ]); |
||
169 | } |
||
170 | |||
171 | /** |
||
172 | * Unblock always blocked user |
||
173 | * @param string $targetId |
||
174 | * @return string |
||
175 | * @throws \Ffcms\Core\Exception\SyntaxException |
||
176 | * @throws ForbiddenException |
||
177 | * @throws NotFoundException |
||
178 | * @throws \Exception |
||
179 | */ |
||
180 | public function actionUnblock($targetId) |
||
181 | { |
||
182 | // check if user is auth |
||
183 | if (!App::$User->isAuth()) { |
||
184 | throw new ForbiddenException(); |
||
185 | } |
||
186 | |||
187 | // check if target is defined |
||
188 | View Code Duplication | if (!Any::isInt($targetId) || $targetId < 1 || !App::$User->isExist($targetId)) { |
|
189 | throw new NotFoundException(); |
||
190 | } |
||
191 | |||
192 | $user = App::$User->identity(); |
||
193 | |||
194 | // check if target user in blacklist of current user |
||
195 | if (!Blacklist::have($user->getId(), $targetId)) { |
||
196 | throw new NotFoundException(); |
||
197 | } |
||
198 | |||
199 | $model = new FormIgnoreDelete($user, $targetId); |
||
251 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.