Passed
Push — master ( f544e7...a87104 )
by Nicklas
02:21
created

AdminController::getPostAdminCreateUser()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 9

Duplication

Lines 15
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 15
loc 15
ccs 0
cts 10
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 9
nc 1
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 ProfileController
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
        $users = $user->findAll();
27
28 2
        return array_map(function ($user) {
29 2
            $user->setGravatar($user->email);
30
31 2
            return $user;
32 2
        }, $users);
33
    }
34
35
    /**
36
     * check if user is logged in
37
     *
38
     * @return void
39
     */
40 1
    public function checkIsAdmin()
41
    {
42 1
        $this->checkIsLogin();
43
44 1
        $user = new User($this->di->get("db"));
45 1
        $user = $user->find("name", $this->di->get("session")->get("user"));
46
47 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...
48
            $views = [
49 1
                ["admin/fail", [], "main"]
50 1
            ];
51 1
            $this->di->get("pageRenderComment")->renderPage([
52 1
                "views" => $views,
53
                "title" => "Not authorized"
54 1
            ]);
55 1
        }
56 1
    }
57
58
59
    /**
60
     * Description.
61
     *
62
     * @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...
63
     *
64
     * @throws Exception
65
     *
66
     * @return void
67
     */
68 1
    public function getUsersIndex()
69
    {
70
        $views = [
71 1
            ["admin/navbar", [], "main"],
72 1
            ["admin/crud/view-all", ["users" => $this->getUsers()], "main"]
73 1
        ];
74
75 1
        $this->di->get("pageRenderComment")->renderPage([
76 1
            "views" => $views,
77
            "title" => "A collection of users"
78 1
        ]);
79 1
    }
80
81
82
    /**
83
     * Description.
84
     *
85
     * @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...
86
     *
87
     * @throws Exception
88
     *
89
     * @return void
90
     */
91 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...
92
    {
93 1
        $form = new EditUserForm($this->di, $id);
94 1
        $form->check();
95
96
        $views = [
97 1
            ["admin/navbar", [], "main"],
98 1
            ["admin/crud/edit", ["form" => $form->getHTML()], "main"]
99 1
        ];
100
101 1
        $this->di->get("pageRenderComment")->renderPage([
102 1
            "views" => $views,
103
            "title" => "Edit user"
104 1
        ]);
105 1
    }
106
107
    /**
108
     * Description.
109
     *
110
     * @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...
111
     *
112
     * @throws Exception
113
     *
114
     * @return void
115
     */
116 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...
117
    {
118
        $form = new CreateUserForm2($this->di);
119
        $form->check();
120
121
        $views = [
122
            ["admin/navbar", [], "main"],
123
            ["admin/crud/edit", ["form" => $form->getHTML()], "main"]
124
        ];
125
126
        $this->di->get("pageRenderComment")->renderPage([
127
            "views" => $views,
128
            "title" => "Create user"
129
        ]);
130
    }
131
}
132