Passed
Push — master ( a3411b...1483ea )
by Nicklas
02:38
created

ProfileController::getPostEditUser()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 11

Duplication

Lines 18
Ratio 100 %

Code Coverage

Tests 12
CRAP Score 1

Importance

Changes 0
Metric Value
dl 18
loc 18
ccs 12
cts 12
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 11
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Nicklas\Comment;
4
5
use \Nicklas\Comment\HTMLForm\Profile\EditProfileForm;
6
use \Nicklas\Comment\HTMLForm\Profile\UpdateProfileSecurityForm;
7
use \Nicklas\Comment\Modules\User;
8
9
/**
10
 * A controller class.
11
 */
12
class ProfileController extends LoginController
13
{
14
15
    /**
16
     * Get details on item to load form with.
17
     *
18
     * @param integer $id get details on item with id.
0 ignored issues
show
Bug introduced by
There is no parameter named $id. 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...
19
     *
20
     * @return object true if okey, false if something went wrong.
21
     */
22 2
    public function getUserDetails($name)
23
    {
24 2
        $user = new User($this->di->get("db"));
25 2
        return $user->getUser($name);
26
    }
27
28
    /**
29
     * Render profile page
30
     *
31
     * @return void
32
     */
33 1
    public function renderProfile()
34
    {
35 1
        $this->checkIsLogin();
36
37 1
        $name = $this->di->get('session')->get("user");
38 1
        $user = $this->getUserDetails($name);
39
40
41
        $views = [
42 1
            ["comment/user/profile/profile", ["user" => $user], "main"]
43 1
        ];
44
45 1
        if ($user->authority == "admin") {
46
            $views = [
47 1
                ["comment/admin/navbar", [], "main"],
48 1
                ["comment/user/profile/profile", ["user" => $user], "main"]
49 1
            ];
50 1
        }
51
52 1
        $this->di->get("pageRenderComment")->renderPage([
53 1
            "views" =>  $views,
54 1
            "title" => "$user->name"
55 1
        ]);
56 1
    }
57
58
    /**
59
     * Description.
60
     *
61
     *
62
     * @return void
63
     */
64 1 View Code Duplication
    public function getPostEditUser()
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...
65
    {
66 1
        $this->checkIsLogin();
67 1
        $name = $this->di->get('session')->get("user");
68 1
        $user = $this->getUserDetails($name);
69
70 1
        $form       = new EditProfileForm($this->di, $name);
71 1
        $form->check();
72
73
        $views = [
74 1
            ["comment/user/profile/edit", ["form" => $form->getHTML(), "user" => $user], "main"]
75 1
        ];
76
77 1
        $this->di->get("pageRenderComment")->renderPage([
78 1
            "views" =>  $views,
79
            "title" => "Edit Profile"
80 1
        ]);
81 1
    }
82
83
    /**
84
     * Description.
85
     *
86
     *
87
     * @return void
88
     */
89 View Code Duplication
    public function getPostEditSecurity()
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...
90
    {
91
        $name = $this->di->get('session')->get("user");
92
        $user = $this->getUserDetails($name);
93
94
        $form       = new UpdateProfileSecurityForm($this->di);
95
        $form->check();
96
97
        $views = [
98
            ["comment/user/profile/edit", ["form" => $form->getHTML(), "user" => $user], "main"]
99
        ];
100
101
        $this->di->get("pageRenderComment")->renderPage([
102
            "views" =>  $views,
103
            "title" => "Edit Profile"
104
        ]);
105
    }
106
}
107