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

ActionPassword::password()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 24
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 24
rs 9.9
c 0
b 0
f 0
cc 4
nc 3
nop 0
1
<?php
2
3
4
namespace Apps\Controller\Front\Profile;
5
6
use Apps\Model\Front\Profile\FormPasswordChange;
7
use Ffcms\Core\App;
8
use Ffcms\Core\Arch\View;
9
use Ffcms\Core\Exception\ForbiddenException;
10
use Ffcms\Core\Network\Response;
11
use Symfony\Component\HttpFoundation\Request;
12
13
/**
14
 * Trait ActionPassword
15
 * @package Apps\Controller\Front\Profile
16
 * @property View $view
17
 * @property Request $request
18
 * @property Response $response
19
 * @method array getConfigs
20
 */
21
trait ActionPassword
22
{
23
24
    /**
25
     * Action change user password
26
     * @return string
27
     * @throws \Ffcms\Core\Exception\SyntaxException
28
     * @throws ForbiddenException
29
     */
30
    public function password(): ?string
31
    {
32
        // check if user is authed
33
        if (!App::$User->isAuth()) {
34
            throw new ForbiddenException();
35
        }
36
37
        // get user object and create model with user object
38
        $user = App::$User->identity();
39
        $model = new FormPasswordChange($user);
0 ignored issues
show
Bug introduced by
It seems like $user can also be of type null; however, parameter $user of Apps\Model\Front\Profile...rdChange::__construct() 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

39
        $model = new FormPasswordChange(/** @scrutinizer ignore-type */ $user);
Loading history...
40
41
        // check if form is submited and validation is passed
42
        if ($model->send() && $model->validate()) {
43
            $model->make();
44
            App::$Event->run(static::EVENT_CHANGE_PASSWORD, [
0 ignored issues
show
Bug introduced by
The constant Apps\Controller\Front\Pr...::EVENT_CHANGE_PASSWORD was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
45
                'model' => $model
46
            ]);
47
48
            App::$Session->getFlashBag()->add('success', __('Password is successful changed'));
49
        }
50
51
        // set response output
52
        return $this->view->render('profile/password', [
53
            'model' => $model
54
        ]);
55
    }
56
}
57