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

ProfileController   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 102
Duplicated Lines 33.33 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 65.12%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 4
dl 34
loc 102
ccs 28
cts 43
cp 0.6512
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getUserDetails() 0 7 1
B renderProfile() 0 24 2
A getPostEditUser() 17 17 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 UserController
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
        $user->find("name", $name);
26 2
        $user->setGravatar();
27 2
        return $user;
28
    }
29
30
    /**
31
     * Render profile page
32
     *
33
     * @return void
34
     */
35 1
    public function renderProfile()
36
    {
37 1
        $this->checkIsLogin();
38
39 1
        $name = $this->di->get('session')->get("user");
40 1
        $user = $this->getUserDetails($name);
41
42
43
        $views = [
44 1
            ["user/profile/profile", ["user" => $user], "main"]
45 1
        ];
46
47 1
        if ($user->authority == "admin") {
48
            $views = [
49
                ["admin/navbar", [], "main"],
50
                ["user/profile/profile", ["user" => $user], "main"]
51
            ];
52
        }
53
54 1
        $this->di->get("pageRenderComment")->renderPage([
55 1
            "views" =>  $views,
56 1
            "title" => "$user->name"
57 1
        ]);
58 1
    }
59
60
    /**
61
     * Description.
62
     *
63
     * @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...
64
     *
65
     * @throws Exception
66
     *
67
     * @return void
68
     */
69 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...
70
    {
71 1
        $name = $this->di->get('session')->get("user");
72 1
        $user = $this->getUserDetails($name);
73
74 1
        $form       = new EditProfileForm($this->di, $name);
75 1
        $form->check();
76
77
        $views = [
78 1
            ["user/profile/edit", ["form" => $form->getHTML(), "user" => $user], "main"]
79 1
        ];
80
81 1
        $this->di->get("pageRenderComment")->renderPage([
82 1
            "views" =>  $views,
83
            "title" => "Edit Profile"
84 1
        ]);
85 1
    }
86
87
    /**
88
     * Description.
89
     *
90
     * @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...
91
     *
92
     * @throws Exception
93
     *
94
     * @return void
95
     */
96 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...
97
    {
98
        $name = $this->di->get('session')->get("user");
99
        $user = $this->getUserDetails($name);
100
101
        $form       = new UpdateProfileSecurityForm($this->di);
102
        $form->check();
103
104
        $views = [
105
            ["user/profile/edit", ["form" => $form->getHTML(), "user" => $user], "main"]
106
        ];
107
108
        $this->di->get("pageRenderComment")->renderPage([
109
            "views" =>  $views,
110
            "title" => "Edit Profile"
111
        ]);
112
    }
113
}
114