UserController   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 88
Duplicated Lines 31.82 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 4
dl 28
loc 88
ccs 0
cts 41
cp 0
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getUserIndex() 0 20 2
A getPostEditPost() 14 14 1
A getPostEditComment() 14 14 1
A getAllUsersIndex() 0 14 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
// MODULES
6
use \Nicklas\Comment\Modules\User;
7
use \Nicklas\Comment\Modules\Post;
8
use \Nicklas\Comment\HTMLForm\Comment\EditPostForm;
9
use \Nicklas\Comment\HTMLForm\Comment\EditCommentForm;
10
11
/**
12
 * A controller class.
13
 */
14
class UserController extends ProfileController
15
{
16
17
    /**
18
     * Create page for all users overview
19
     *
20
     * @return void
21
     */
22
    public function getAllUsersIndex()
23
    {
24
        $user = new User($this->di->get("db"));
25
        $users = $user->getAllUsers();
26
27
        $views = [
28
            ["comment/users/view-all", ["users" => $users], "main"]
29
        ];
30
31
        $this->di->get("pageRenderComment")->renderPage([
32
            "views" => $views,
33
            "title" => "Coffee users"
34
        ]);
35
    }
36
37
    /**
38
     * Create page for all users overview
39
     *
40
     * @return void
41
     */
42
    public function getUserIndex($name)
43
    {
44
        $user = new User($this->di->get("db"));
45
46
        // No exists, return false
47
        if ($user->find("name", $name) == null) {
48
            return false;
49
        }
50
51
        $user = $user->getUser($name);
52
53
        $views = [
54
            ["comment/users/view-user", ["user" => $user], "main"]
55
        ];
56
57
        $this->di->get("pageRenderComment")->renderPage([
58
            "views" => $views,
59
            "title" => "User | $user->name"
60
        ]);
61
    }
62
63
    /**
64
     * Create page for all users overview
65
     *
66
     * @return void
67
     */
68 View Code Duplication
    public function getPostEditPost($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...
69
    {
70
        $form = new EditPostForm($this->di, $id);
71
        $form->check();
72
73
        $views = [
74
            ["comment/default-form", ["form" => $form->getHTML()], "main"]
75
        ];
76
77
        $this->di->get("pageRenderComment")->renderPage([
78
            "views" => $views,
79
            "title" => "Edit post | $id"
80
        ]);
81
    }
82
    /**
83
     * Create page for all users overview
84
     *
85
     * @return void
86
     */
87 View Code Duplication
    public function getPostEditComment($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...
88
    {
89
        $form = new EditCommentForm($this->di, $id);
90
        $form->check();
91
92
        $views = [
93
            ["comment/default-form", ["form" => $form->getHTML()], "main"]
94
        ];
95
96
        $this->di->get("pageRenderComment")->renderPage([
97
            "views" => $views,
98
            "title" => "Edit comment | $id"
99
        ]);
100
    }
101
}
102