Conditions | 4 |
Paths | 4 |
Total Lines | 25 |
Code Lines | 14 |
Lines | 8 |
Ratio | 32 % |
Changes | 0 |
1 | <?php |
||
27 | public function avatar() |
||
28 | { |
||
29 | if (!App::$User->isAuth()) { |
||
30 | throw new ForbiddenException('You must be authorized user!'); |
||
31 | } |
||
32 | |||
33 | // get user identity and model object |
||
34 | $user = App::$User->identity(); |
||
35 | $model = new FormAvatarUpload(true); |
||
36 | |||
37 | // validate model post data |
||
38 | View Code Duplication | if ($model->send()) { |
|
|
|||
39 | if ($model->validate()) { |
||
40 | $model->copyFile($user); |
||
41 | App::$Session->getFlashBag()->add('success', __('Avatar is successful changed')); |
||
42 | } else { |
||
43 | App::$Session->getFlashBag()->add('error', __('File upload is failed!')); |
||
44 | } |
||
45 | } |
||
46 | |||
47 | return $this->view->render('avatar', [ |
||
48 | 'user' => $user, |
||
49 | 'model' => $model |
||
50 | ]); |
||
51 | } |
||
52 | } |
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.