Test Failed
Push — master ( 7c8781...44e581 )
by Nicklas
02:28
created

AdminController::checkIsAdmin()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 17
Code Lines 10

Duplication

Lines 9
Ratio 52.94 %

Code Coverage

Tests 4
CRAP Score 3.1852

Importance

Changes 0
Metric Value
dl 9
loc 17
ccs 4
cts 12
cp 0.3333
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 10
nc 2
nop 0
crap 3.1852
1
<?php
2
3
namespace Nicklas\Comment;
4
5
use \Nicklas\Comment\HTMLForm\Admin\EditUserForm;
6
use \Nicklas\Comment\HTMLForm\Admin\CreateUserForm2;
7
8
// MODULES
9
use \Nicklas\Comment\Modules\User;
10
11
/**
12
 * A controller class.
13
 */
14
class AdminController extends UserController
15
{
16
17
    /**
18
     * Get all users
19
     *
20
     * @return array
21
     */
22 1
    public function getUsers()
23
    {
24 1
        $user = new User($this->di->get("db"));
25 1
        return $user->getAllUsers();
26
    }
27
28
    /**
29
     * check if user is logged in
30
     *
31
     * @return void
32
     */
33 1
    public function checkIsAdmin()
34
    {
35 1
        $this->checkIsLogin();
36
37 1
        $user = new User($this->di->get("db"));
38 1
        $user = $user->getUser($this->di->get("session")->get("user"));
39
40 View Code Duplication
        if ($user->authority != "admin") {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
41
            $views = [
42
                ["comment/admin/fail", [], "main"]
43
            ];
44
            $this->di->get("pageRenderComment")->renderPage([
45
                "views" => $views,
46
                "title" => "Not authorized"
47
            ]);
48
        }
49
    }
50
51
52
    /**
53
     * Description.
54
     *
55
     * @return void
56
     */
57 1
    public function getUsersIndex()
58
    {
59
        $views = [
60 1
            ["comment/admin/navbar", [], "main"],
61 1
            ["comment/admin/crud/view-all", ["users" => $this->getUsers()], "main"]
62
        ];
63
64
        $this->di->get("pageRenderComment")->renderPage([
65
            "views" => $views,
66
            "title" => "A collection of users"
67
        ]);
68
    }
69
70
71
    /**
72
     * Description.
73
     *
74
     * @param int $id
75
     *
76
     * @return void
77
     */
78 1 View Code Duplication
    public function getPostAdminEditUser($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...
79
    {
80 1
        $form = new EditUserForm($this->di, $id);
81
        $form->check();
82
83
        $views = [
84
            ["comment/admin/navbar", [], "main"],
85
            ["comment/admin/crud/edit", ["form" => $form->getHTML()], "main"]
86
        ];
87
88
        $this->di->get("pageRenderComment")->renderPage([
89
            "views" => $views,
90
            "title" => "Edit user"
91
        ]);
92
    }
93
94
    /**
95
     * Description.
96
     *
97
     * @return void
98
     */
99 View Code Duplication
    public function getPostAdminCreateUser()
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...
100
    {
101
        $form = new CreateUserForm2($this->di);
102
        $form->check();
103
104
        $views = [
105
            ["comment/admin/navbar", [], "main"],
106
            ["comment/admin/crud/edit", ["form" => $form->getHTML()], "main"]
107
        ];
108
109
        $this->di->get("pageRenderComment")->renderPage([
110
            "views" => $views,
111
            "title" => "Create user"
112
        ]);
113
    }
114
}
115