Completed
Push — master ( 0a436d...ec1a89 )
by Nicklas
02:25
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 12
CRAP Score 2

Importance

Changes 0
Metric Value
dl 9
loc 17
ccs 12
cts 12
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 10
nc 2
nop 0
crap 2
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
     *
21
     * @return array
22
     */
23 2
    public function getUsers()
24
    {
25 2
        $user = new User($this->di->get("db"));
26 2
        return $user->getAllUsers();
27
    }
28
29
    /**
30
     * check if user is logged in
31
     *
32
     * @return void
33
     */
34 1
    public function checkIsAdmin()
35
    {
36 1
        $this->checkIsLogin();
37
38 1
        $user = new User($this->di->get("db"));
39 1
        $user = $user->getUser($this->di->get("session")->get("user"));
40
41 1 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...
42
            $views = [
43 1
                ["comment/admin/fail", [], "main"]
44 1
            ];
45 1
            $this->di->get("pageRenderComment")->renderPage([
46 1
                "views" => $views,
47
                "title" => "Not authorized"
48 1
            ]);
49 1
        }
50 1
    }
51
52
53
    /**
54
     * Description.
55
     *
56
     * @param datatype $variable Description
0 ignored issues
show
Bug introduced by
There is no parameter named $variable. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
57
     *
58
     * @throws Exception
59
     *
60
     * @return void
61
     */
62 1
    public function getUsersIndex()
63
    {
64
        $views = [
65 1
            ["comment/admin/navbar", [], "main"],
66 1
            ["comment/admin/crud/view-all", ["users" => $this->getUsers()], "main"]
67 1
        ];
68
69 1
        $this->di->get("pageRenderComment")->renderPage([
70 1
            "views" => $views,
71
            "title" => "A collection of users"
72 1
        ]);
73 1
    }
74
75
76
    /**
77
     * Description.
78
     *
79
     * @param datatype $variable Description
0 ignored issues
show
Bug introduced by
There is no parameter named $variable. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
80
     *
81
     * @throws Exception
82
     *
83
     * @return void
84
     */
85 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...
86
    {
87 1
        $form = new EditUserForm($this->di, $id);
88 1
        $form->check();
89
90
        $views = [
91 1
            ["comment/admin/navbar", [], "main"],
92 1
            ["comment/admin/crud/edit", ["form" => $form->getHTML()], "main"]
93 1
        ];
94
95 1
        $this->di->get("pageRenderComment")->renderPage([
96 1
            "views" => $views,
97
            "title" => "Edit user"
98 1
        ]);
99 1
    }
100
101
    /**
102
     * Description.
103
     *
104
     * @param datatype $variable Description
0 ignored issues
show
Bug introduced by
There is no parameter named $variable. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
105
     *
106
     * @throws Exception
107
     *
108
     * @return void
109
     */
110 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...
111
    {
112
        $form = new CreateUserForm2($this->di);
113
        $form->check();
114
115
        $views = [
116
            ["comment/admin/navbar", [], "main"],
117
            ["comment/admin/crud/edit", ["form" => $form->getHTML()], "main"]
118
        ];
119
120
        $this->di->get("pageRenderComment")->renderPage([
121
            "views" => $views,
122
            "title" => "Create user"
123
        ]);
124
    }
125
}
126