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

ProfileController   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 95
Duplicated Lines 36.84 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 73.81%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 4
dl 35
loc 95
ccs 31
cts 42
cp 0.7381
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getUserDetails() 0 5 1
B renderProfile() 0 24 2
A getPostEditUser() 18 18 1
A getPostEditSecurity() 17 17 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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