UserController::getIndex()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 21
Code Lines 14

Duplication

Lines 17
Ratio 80.95 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 14
nc 2
nop 0
dl 17
loc 21
ccs 0
cts 15
cp 0
crap 6
rs 9.3142
c 0
b 0
f 0
1
<?php
2
3
namespace Anax\User;
4
5
use \Anax\Configure\ConfigureInterface;
6
use \Anax\Configure\ConfigureTrait;
7
use \Anax\DI\InjectionAwareInterface;
8
use \Anax\Di\InjectionAwareTrait;
9
use \Anax\User\HTMLForm\UserLoginForm;
10
use \Anax\User\HTMLForm\CreateUserForm;
11
use \Anax\User\User;
12
use \Anax\User\HTMLForm\UpdateForm;
13
14
/**
15
 * A controller class.
16
 */
17
class UserController implements
18
    ConfigureInterface,
19
    InjectionAwareInterface
20
{
21
    use ConfigureTrait,
22
        InjectionAwareTrait;
23
24
25
26
    /**
27
     * @var $data description
28
     */
29
    //private $data;
30
31
32
33
    /**
34
     * Description.
35
     *
36
     * @param datatype $variable Description
0 ignored issues
show
Bug introduced by
There is no parameter named $variable. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
37
     *
38
     * @throws Exception
39
     *
40
     * @return void
41
     */
42
    public function getIndex()
43
    {
44
        $session = $this->di->get("session");
45 View Code Duplication
        if ($session->has("username")) {
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...
46
            $user = new User();
47
            $user->setDb($this->di->get("db"));
48
            $title      = "Profile";
49
            $view       = $this->di->get("view");
50
            $pageRender = $this->di->get("pageRender");
51
52
            $data = [
53
                "content" => $user->getUserData($session->get("username")),
54
            ];
55
56
            $view->add("user/profile", $data);
57
58
            $pageRender->renderPage(["title" => $title]);
59
        } else {
60
            $this->di->get("response")->redirect("user/login");
61
        }
62
    }
63
64
65
66
    /**
67
     * Description.
68
     *
69
     * @param datatype $variable Description
0 ignored issues
show
Bug introduced by
There is no parameter named $variable. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
70
     *
71
     * @throws Exception
72
     *
73
     * @return void
74
     */
75 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...
76
    {
77
        $title      = "Login";
78
        $view       = $this->di->get("view");
79
        $pageRender = $this->di->get("pageRender");
80
        $form       = new UserLoginForm($this->di);
81
82
        $form->check();
83
84
        $data = [
85
            "content" => $form->getHTML(),
86
        ];
87
88
        $view->add("login/login", $data);
89
90
        $pageRender->renderPage(["title" => $title]);
91
    }
92
93
94
95
    /**
96
     * Description.
97
     *
98
     * @param datatype $variable Description
0 ignored issues
show
Bug introduced by
There is no parameter named $variable. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
99
     *
100
     * @throws Exception
101
     *
102
     * @return void
103
     */
104 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...
105
    {
106
        $title      = "A create user page";
107
        $view       = $this->di->get("view");
108
        $pageRender = $this->di->get("pageRender");
109
        $form       = new CreateUserForm($this->di);
110
111
        $form->check();
112
113
        $data = [
114
            "content" => $form->getHTML(),
115
        ];
116
117
        $view->add("default2/article", $data);
118
119
        $pageRender->renderPage(["title" => $title]);
120
    }
121
122
    /**
123
     * Handler with form to update an item.
124
     *
125
     * @return void
126
     */
127 View Code Duplication
    public function getPostUpdateUser($id)
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...
128
    {
129
        $title      = "Updatera användare";
130
        $view       = $this->di->get("view");
131
        $pageRender = $this->di->get("pageRender");
132
        $form       = new UpdateForm($this->di, $id);
133
134
        $form->check();
135
136
        $data = [
137
            "form" => $form->getHTML(),
138
        ];
139
140
        $view->add("user/update", $data);
141
142
        $pageRender->renderPage(["title" => $title]);
143
    }
144
145
    /**
146
     * Logout the user
147
     *
148
     * @return void
149
     */
150
    public function logoutUser()
151
    {
152
        $this->di->get("session")->destroy();
153
        $this->di->get("response")->redirect("user/login");
154
    }
155
156
    /**
157
     * Render admin page with all users
158
     *
159
     * @return void
160
     */
161
    public function getAdminIndex()
162
    {
163 View Code Duplication
        if ($this->di->get("session")->has("admin")) {
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...
164
            $title      = "Admin";
165
            $user       = new User();
166
            $user->setDb($this->di->get("db"));
167
            $view       = $this->di->get("view");
168
            $pageRender = $this->di->get("pageRender");
169
170
171
            $data = [
172
                "users" => $user->findAll(),
173
            ];
174
175
            $view->add("user/admin", $data);
176
177
            $pageRender->renderPage(["title" => $title]);
178
        } else {
179
            $this->di->get("response")->redirect("user/profile");
180
        }
181
    }
182
183
    /**
184
     * Delete a user
185
     *
186
     *@var integer id of user to delete
187
     *
188
     * @return void
189
     */
190
    public function adminDeleteUser($id)
191
    {
192
        if ($this->di->get("session")->has("admin")) {
193
            $user       = new User();
194
            $user->setDb($this->di->get("db"));
195
            $user->delete($id);
196
            $this->di->get("response")->redirect("user/admin");
197
        } else {
198
            $this->di->get("response")->redirect("user/profile");
199
        }
200
    }
201
}
202