AdminController::init()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 7
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 0
dl 7
loc 7
ccs 0
cts 6
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 AdminController implements InjectionAwareInterface
17
{
18
    use InjectionAwareTrait;
19
20
21
22
    /**
23
     * Init module
24
     */
25 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
        $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
        $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
        $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
        $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
        $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
    }
33
34
35
36
    public function isAdmin()
37
    {
38
        $admin = $this->user->getUser()->admin;
39
        if (!$admin) {
40
            $this->response->redirect("user");
41
        }
42
    }
43
44
45
46
    /**
47
     * Description.
48
     *
49
     * @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...
50
     *
51
     * @throws Exception
52
     *
53
     * @return void
54
     */
55
    public function getIndex()
56
    {
57
        $title = "Admin | All users";
58
59
        $data = $this->user->getAllUsers('email', $this->session->get('user')) ?: [];
60
61
        $this->view->add("admin/index", ["users" => $data]);
62
        $this->pageRender->renderPage(["title" => $title]);
63
    }
64
65
66
67 View Code Duplication
    public function editUser($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...
68
    {
69
        $title = "Admin | Edit user";
70
71
        $user = $this->user->getUser("id", $id);
72
73
        $form = new UpdateUserForm($this->di, $user);
74
        $form->check();
75
76
        $data = $this->user->getUser('id', $id);
77
78
        $this->view->add("user/profile", ["user" => $data, "form" => $form->getHTML()]);
79
        $this->pageRender->renderPage(["title" => $title]);
80
    }
81
82
83
84
    public function deleteUser($id)
85
    {
86
        $this->user->delete($id);
87
        $this->response->redirect("admin");
88
    }
89
}
90