Passed
Push — master ( 3de7ee...b534e3 )
by Mihail
14:25
created

ActionAvatar   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 33
Duplicated Lines 24.24 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
dl 8
loc 33
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 5

1 Method

Rating   Name   Duplication   Size   Complexity  
B avatar() 8 25 4

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
4
namespace Apps\Controller\Front\Profile;
5
6
use Apps\Model\Front\Profile\FormAvatarUpload;
7
use Ffcms\Core\App;
8
use Ffcms\Core\Arch\View;
9
use Ffcms\Core\Exception\ForbiddenException;
10
use Ffcms\Core\Network\Request;
11
use Ffcms\Core\Network\Response;
12
13
/**
14
 * Trait ActionAvatar
15
 * @package Apps\Controller\Front\Profile
16
 * @property View $view
17
 * @property Request $request
18
 * @property Response $response
19
 */
20
trait ActionAvatar
21
{
22
    /**
23
     * User avatar management
24
     * @throws \Ffcms\Core\Exception\SyntaxException
25
     * @throws ForbiddenException
26
     */
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()) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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.

Loading history...
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
}