UserController::getPostUpdate()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 11

Duplication

Lines 18
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 18
loc 18
ccs 0
cts 12
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 11
nc 1
nop 0
crap 2
1
<?php
2
3
namespace Almrooth\Comment;
4
5
use \Anax\Configure\ConfigureInterface;
6
use \Anax\Configure\ConfigureTrait;
7
use \Anax\DI\InjectionAwareInterface;
8
use \Anax\DI\InjectionAwareTrait;
9
10
use \Almrooth\Comment\HTMLForm\LoginForm;
11
use \Almrooth\Comment\HTMLForm\RegisterForm;
12
use \Almrooth\Comment\HTMLForm\UpdateUserForm;
13
14
/**
15
 * A controller class.
16
 * @SuppressWarnings("camelcase")
17
 */
18
class UserController implements
19
    ConfigureInterface,
20
    InjectionAwareInterface
21
{
22
    use ConfigureTrait,
23
        InjectionAwareTrait;
24
25
26
    /**
27
     * @var $data description
28
     */
29
    //private $data;
30
31
32
    /**
33
     * Handler with form to login user
34
     *
35
     * @return void
36
     */
37
    public function getPostLogin()
38
    {
39
        $title      = "Login";
40
        $view       = $this->di->get("view");
41
        $pageRender = $this->di->get("pageRender");
42
        $form       = new LoginForm($this->di);
43
44
        $form->check();
45
46
        $data = [
47
            "form" => $form->getHTML(),
48
        ];
49
50
        $view->add("user/login", $data);
51
52
        $pageRender->renderPage(["title" => $title]);
53
    }
54
55
56
    // Handle user logout
57
    public function getLogout()
58
    {
59
        $this->di->get("session")->destroy();
60
        $this->di->get("response")->redirect("user/login");
61
    }
62
63
64
    /**
65
     * Handler with form to register new user
66
     *
67
     * @return void
68
     */
69
    public function getPostRegister()
70
    {
71
        $title      = "Registrera";
72
        $view       = $this->di->get("view");
73
        $pageRender = $this->di->get("pageRender");
74
        $form       = new RegisterForm($this->di);
75
76
        $form->check();
77
78
        $data = [
79
            "form" => $form->getHTML(),
80
        ];
81
82
        $view->add("user/register", $data);
83
84
        $pageRender->renderPage(["title" => $title]);
85
    }
86
87
88
    // Handle user profile page
89
    public function getProfile($id)
90
    {
91
        $title      = "Profil";
92
        $view       = $this->di->get("view");
93
        $pageRender = $this->di->get("pageRender");
94
95
        $user = new User();
96
        $user->setDb($this->di->get("db"));
97
        $user->find("id", $id);
98
99
        $data = [
100
            "user" => $user
101
        ];
102
103
        $view->add("user/profile", $data);
104
        
105
        $pageRender->renderPage(["title" => $title]);
106
    }
107
108
109 View Code Duplication
    public function getPostUpdate()
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...
110
    {
111
        $title      = "Updatera profil";
112
        $view       = $this->di->get("view");
113
        $pageRender = $this->di->get("pageRender");
114
        $user_id    = $this->di->get("session")->get("user_id");
115
        $form       = new UpdateUserForm($this->di, $user_id);
116
117
        $form->check();
118
119
        $data = [
120
            "form" => $form->getHTML()
121
        ];
122
123
        $view->add("user/update", $data);
124
        
125
        $pageRender->renderPage(["title" => $title]);
126
    }
127
}
128