Test Failed
Push — master ( e3c39f...fe570d )
by Mihail
07:20
created

Apps/Controller/Front/Profile/ActionAvatar.php (1 issue)

Labels
Severity
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(): ?string
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
        if ($model->send()) {
39
            if ($model->validate()) {
40
                $model->copyFile($user);
0 ignored issues
show
It seems like $user can also be of type null; however, parameter $user of Apps\Model\Front\Profile...vatarUpload::copyFile() does only seem to accept Ffcms\Core\Interfaces\iUser, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

40
                $model->copyFile(/** @scrutinizer ignore-type */ $user);
Loading history...
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('profile/avatar', [
48
            'user' => $user,
49
            'model' => $model
50
        ]);
51
    }
52
}
53