UserController::getPostCreateUser()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 9
nc 1
nop 0
dl 0
loc 16
ccs 0
cts 9
cp 0
crap 2
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Alvo\User;
4
5
use \Anax\Configure\ConfigureInterface;
6
use \Anax\Configure\ConfigureTrait;
7
use \Anax\DI\InjectionAwareInterface;
8
use \Anax\Di\InjectionAwareTrait;
9
use \Alvo\User\HTMLForm\UserLoginForm;
10
use \Alvo\User\HTMLForm\CreateUserForm;
11
use \Alvo\User\HTMLForm\UpdateUserForm;
12
13
/**
14
 * A controller class.
15
 */
16
class UserController implements InjectionAwareInterface
17
{
18
    use InjectionAwareTrait;
19
20
21
22
    /**
23
     * Init module
24
     */
25 1 View Code Duplication
    public function init()
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...
26
    {
27 1
        $this->session = $this->di->get("session");
0 ignored issues
show
Bug Best Practice introduced by
The property session does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
28 1
        $this->response = $this->di->get("response");
0 ignored issues
show
Bug Best Practice introduced by
The property response does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
29 1
        $this->user = $this->di->get("user");
0 ignored issues
show
Bug Best Practice introduced by
The property user does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
30 1
        $this->view = $this->di->get("view");
0 ignored issues
show
Bug Best Practice introduced by
The property view does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
31 1
        $this->pageRender = $this->di->get("pageRender");
0 ignored issues
show
Bug Best Practice introduced by
The property pageRender does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
32 1
    }
33
34
35
36
    /**
37
     * Description.
38
     *
39
     * @param datatype $variable Description
0 ignored issues
show
Bug introduced by
The type Alvo\User\datatype was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
40
     *
41
     * @throws Exception
42
     *
43
     * @return void
44
     */
45
    public function getIndex()
46
    {
47
        if (!$this->user->isLoggedIn()) {
48
            $this->response->redirect('user/login');
49
        }
50
51
        $title = "Profile";
52
53
        $form = new UpdateUserForm($this->di);
54
        $form->check();
55
56
        $user = $this->user->find("id", $this->session->get("userId"));
57
        // debug($user);
58
59
        $data = $this->user->getUser('email', $user->email);
60
61
        $this->view->add("user/profile", ["user" => $data, "form" => $form->getHTML()]);
62
63
        $this->pageRender->renderPage(["title" => $title]);
64
    }
65
66
67
68
    /**
69
     * Description.
70
     *
71
     * @param datatype $variable Description
72
     *
73
     * @throws Exception
74
     *
75
     * @return void
76
     */
77 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...
78
    {
79
        if ($this->user->isLoggedIn()) {
80
            $this->response->redirect("user");
81
        }
82
83
        $title      = "A login page";
84
        $view       = $this->di->get("view");
85
        $pageRender = $this->di->get("pageRender");
86
        $form       = new UserLoginForm($this->di);
87
88
        $form->check();
89
90
        $data = [
91
            "content" => $form->getHTML(),
92
        ];
93
94
        // var_dump($form);
95
        // exit;
96
        // $this->utils->login()
97
98
        // $response->redirect('user');
99
100
        $view->add("default2/article", $data);
101
102
        $pageRender->renderPage(["title" => $title]);
103
    }
104
105
106
107
    /**
108
     * Description.
109
     *
110
     * @param datatype $variable Description
111
     *
112
     * @throws Exception
113
     *
114
     * @return void
115
     */
116
    public function getPostCreateUser()
117
    {
118
        $title      = "A create user page";
119
        $view       = $this->di->get("view");
120
        $pageRender = $this->di->get("pageRender");
121
        $form       = new CreateUserForm($this->di);
122
123
        $form->check();
124
125
        $data = [
126
            "content" => $form->getHTML(),
127
        ];
128
129
        $view->add("default2/article", $data);
130
131
        $pageRender->renderPage(["title" => $title]);
132
    }
133
134
135
136
    public function logout()
137
    {
138
        $this->user->logout();
139
        $this->response->redirect("user/login");
140
    }
141
}
142