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

ActionAvatar::avatar()   B

Complexity

Conditions 4
Paths 4

Size

Total Lines 25
Code Lines 14

Duplication

Lines 8
Ratio 32 %

Importance

Changes 0
Metric Value
cc 4
eloc 14
nc 4
nop 0
dl 8
loc 25
rs 8.5806
c 0
b 0
f 0
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
}