LoginController   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 105
Duplicated Lines 48.57 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 52.5%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
lcom 1
cbo 5
dl 51
loc 105
ccs 21
cts 40
cp 0.525
rs 10
c 1
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A logout() 0 5 1
A checkIsLogin() 9 12 2
A getPostLogin() 14 14 1
A getPostReset() 14 14 1
A getPostCreateUser() 14 14 1

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
namespace Nicklas\Comment;
4
5
// ANAX
6
use \Anax\Configure\ConfigureInterface;
7
use \Anax\Configure\ConfigureTrait;
8
use \Anax\DI\InjectionAwareInterface;
9
use \Anax\DI\InjectionAwareTrait;
10
11
// HTMLforms
12
use \Nicklas\Comment\HTMLForm\User\UserLoginForm;
13
use \Nicklas\Comment\HTMLForm\User\CreateUserForm;
14
use \Nicklas\Comment\HTMLForm\User\UserResetForm;
15
16
// MODULES
17
use \Nicklas\Comment\Modules\User;
18
19
/**
20
 * A controller class.
21
 */
22
class LoginController implements
23
    ConfigureInterface,
24
    InjectionAwareInterface
25
{
26
    use ConfigureTrait, InjectionAwareTrait;
27
28
    /**
29
     * Logout user by setting "user" == null in session.
30
     *
31
     * @return void
32
     */
33
    public function logout()
34
    {
35
        $this->di->get('session')->set("user", null);
36
        $this->di->get("response")->redirect("user/login");
37
    }
38
39
40
    /**
41
     * check if user is logged in
42
     *
43
     * @return void
44
     */
45 2
    public function checkIsLogin()
46
    {
47 2 View Code Duplication
        if (!$this->di->get("session")->has("user")) {
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...
48
            $views = [
49
                ["comment/user/fail/fail", [], "main"]
50
            ];
51
            $this->di->get("pageRenderComment")->renderPage([
52
                "views" => $views,
53
                "title" => "Not logged in"
54
            ]);
55
        }
56 2
    }
57
58
59
60
61
    /**
62
     * Description.
63
     *
64
     * @throws Exception
65
     *
66
     * @return void
67
     */
68 1 View Code Duplication
    public function getPostLogin()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
69
    {
70 1
        $form       = new UserLoginForm($this->di);
71 1
        $form->check();
72
73
        $views = [
74 1
            ["comment/user/pre/login", ["form" => $form->getHTML()], "main"]
75 1
        ];
76
77 1
        $this->di->get("pageRenderComment")->renderPage([
78 1
            "views" => $views,
79
            "title" => "Login"
80 1
        ]);
81 1
    }
82
83
    /**
84
    * Description.
85
    *
86
    * @return void
87
    */
88 View Code Duplication
    public function getPostReset()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
89
    {
90
        $form       = new UserResetForm($this->di);
91
        $form->check();
92
93
        $views = [
94
            ["comment/user/pre/reset", ["form" => $form->getHTML()], "main"]
95
        ];
96
97
        $this->di->get("pageRenderComment")->renderPage([
98
            "views" => $views,
99
            "title" => "Reset password"
100
        ]);
101
    }
102
103
104
105
    /**
106
     * Description.
107
     *
108
     * @throws Exception
109
     *
110
     * @return void
111
     */
112 1 View Code Duplication
    public function getPostCreateUser()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
113
    {
114 1
        $form       = new CreateUserForm($this->di);
115 1
        $form->check();
116
117
        $views = [
118 1
            ["comment/user/pre/create", ["form" => $form->getHTML()], "main"]
119 1
        ];
120
121 1
        $this->di->get("pageRenderComment")->renderPage([
122 1
            "views" => $views,
123
            "title" => "Create User"
124 1
        ]);
125 1
    }
126
}
127