ProfileController   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 26
dl 0
loc 67
ccs 27
cts 27
cp 1
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A indexActionGet() 0 20 2
A updateAction() 0 12 1
A logoutAction() 0 6 1
1
<?php
2
3
namespace Seb\Profile;
4
5
use Anax\Commons\ContainerInjectableInterface;
6
use Anax\Commons\ContainerInjectableTrait;
7
use Seb\Profile\HTMLForm\UpdateForm;
8
9
/**
10
 * A sample controller to show how a controller class can be implemented.
11
 */
12
class ProfileController implements ContainerInjectableInterface
13
{
14
    use ContainerInjectableTrait;
15
16
    /**
17
     * Show all items.
18
     *
19
     * @return object as a response object
20
     */
21 1
    public function indexActionGet() : object
22
    {
23 1
        $page = $this->di->get("page");
24 1
        $session = $this->di->get("session");
25 1
        $acronym = $session->get("acronym");
26 1
        $profile = new Profile();
27 1
        $profile->setDb($this->di->get("dbqb"));
28
29 1
        if (!$session->get("acronym")) {
30 1
            $page->add("user/please");
31 1
            return $page->render();
32
        }
33
34 1
        $page->add("user/profile", [
35 1
            "userInfo" => $profile->findAll(),
36 1
            "acro" => $acronym
37
        ]);
38
39 1
        return $page->render([
40 1
            "title" => "Profile",
41
        ]);
42
    }
43
44
    /**
45
     * Handler with form to update an item.
46
     *
47
     * @param int $id the id to update.
48
     *
49
     * @return object as a response object
50
     */
51 1
    public function updateAction(int $id) : object
52
    {
53 1
        $page = $this->di->get("page");
54 1
        $form = new UpdateForm($this->di, $id);
55 1
        $form->check();
56
57 1
        $page->add("user/update", [
58 1
            "form" => $form->getHTML(),
59
        ]);
60
61 1
        return $page->render([
62 1
            "title" => "Update an item",
63
        ]);
64
    }
65
66
    /**
67
     * Handler with form to update an item.
68
     *
69
     * @param int $id the id to update.
70
     *
71
     * @return object as a response object
72
     */
73 1
    public function logoutAction()
74
    {
75 1
        $session = $this->di->get("session");
76 1
        $session->set("acronym", null);
77 1
        $session->set("userid", null);
78 1
        $this->di->get("response")->redirect("user/login")->send();
79 1
    }
80
}
81