Passed
Push — master ( b534e3...17b30a )
by Mihail
19:51
created

ActionPassword   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 22.22 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 8
loc 36
rs 10
wmc 4
lcom 1
cbo 6

1 Method

Rating   Name   Duplication   Size   Complexity  
B password() 8 26 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\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()
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);
40
41
        // check if form is submited and validation is passed
42 View Code Duplication
        if ($model->send() && $model->validate()) {
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...
43
            $model->make();
44
            App::$Event->run(static::EVENT_CHANGE_PASSWORD, [
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('password', [
53
            'model' => $model
54
        ]);
55
    }
56
}
57