UserController::indexAction()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 16
ccs 0
cts 11
cp 0
rs 9.9
c 0
b 0
f 0
cc 2
nc 2
nop 0
crap 6
1
<?php
2
3
namespace Anax\User;
4
5
use Anax\Commons\ContainerInjectableInterface;
6
use Anax\Commons\ContainerInjectableTrait;
7
use Anax\User\HTMLForm\UserLoginForm;
8
use Anax\User\HTMLForm\CreateUserForm;
9
10
// use Anax\Route\Exception\ForbiddenException;
11
// use Anax\Route\Exception\NotFoundException;
12
// use Anax\Route\Exception\InternalErrorException;
13
14
/**
15
 * A sample controller to show how a controller class can be implemented.
16
 */
17
class UserController implements ContainerInjectableInterface
18
{
19
    use ContainerInjectableTrait;
20
21
    /**
22
     * @var $data description
23
     */
24
    //private $data;
25
26
27
28
    // /**
29
    //  * The initialize method is optional and will always be called before the
30
    //  * target method/action. This is a convienient method where you could
31
    //  * setup internal properties that are commonly used by several methods.
32
    //  *
33
    //  * @return void
34
    //  */
35
    // public function initialize() : void
36
    // {
37
    //     ;
38
    // }
39
40
    /**
41
     * Description.
42
     *
43
     * @param datatype $variable Description
0 ignored issues
show
Bug introduced by
The type Anax\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...
44
     *
45
     * @throws Exception
46
     *
47
     * @return object as a response object
48
     */
49
    public function indexAction() : object
50
    {
51
        $page = $this->di->get("page");
52
        $form = new UserLoginForm($this->di);
53
        $form->check();
54
        $session = $this->di->get("session");
55
        if ($session->has("login")) {
56
            $page->add("login/index");
57
        } else {
58
            $page->add("anax/v2/article/default", [
59
                "content" => $form->getHTML(),
60
            ]);
61
        }
62
63
        return $page->render([
64
            "title" => "Login",
65
        ]);
66
    }
67
68
69
70
    /**
71
     * Description.
72
     *
73
     * @param datatype $variable Description
74
     *
75
     * @throws Exception
76
     *
77
     * @return object as a response object
78
     */
79
    public function createAction() : object
80
    {
81
        $page = $this->di->get("page");
82
        $form = new CreateUserForm($this->di);
83
        $form->check();
84
85
        $page->add("anax/v2/article/default", [
86
            "content" => $form->getHTML(),
87
        ]);
88
89
        return $page->render([
90
            "title" => "A create user page",
91
        ]);
92
    }
93
94
    public function logoutAction()
95
    {
96
        $session = $this->di->get("session");
97
        $session->destroy();
98
        $this->di->get("response")->redirect("login");
99
    }
100
}
101