CommentController   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 87
Duplicated Lines 24.14 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
c 1
b 0
f 0
lcom 1
cbo 1
dl 21
loc 87
ccs 0
cts 30
cp 0
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A viewAll() 7 7 1
A newPost() 0 5 1
A newPostAction() 0 5 1
A showOnePost() 7 7 1
A editPost() 7 7 1
A editPostAction() 0 5 1
A removePost() 0 4 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 Schanihbg\Comment;
4
5
use \Anax\DI\InjectionAwareInterface;
6
use \Anax\DI\InjectionAwareTrait;
7
8
/**
9
 * A controller for the REM Server.
10
 *
11
 * @SuppressWarnings(PHPMD.ExitExpression)
12
 */
13
class CommentController implements InjectionAwareInterface
14
{
15
    use InjectionAwareTrait;
16
17
18
    /**
19
     * View all posts
20
     *
21
     * @return void
22
     */
23 View Code Duplication
    public function viewAll()
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...
24
    {
25
        $data = $this->di->get("comment")->viewAll();
26
27
        $this->di->get("view")->add("comment/main", ["content" => $data]);
28
        $this->di->get("pageRender")->renderPage(["title" => "All comments"]);
29
    }
30
31
    /**
32
     * New post
33
     *
34
     * @return void
35
     */
36
    public function newPost()
37
    {
38
        $this->di->get("view")->add("comment/new_comment");
39
        $this->di->get("pageRender")->renderPage(["title" => "New comment"]);
40
    }
41
42
    /**
43
     * New post page
44
     *
45
     * @return void
46
     */
47
    public function newPostAction()
48
    {
49
        $this->di->get("view")->add("comment/new_comment_action");
50
        $this->di->get("pageRender")->renderPage(["title" => "New comment action"]);
51
    }
52
53
    /**
54
     * Show one post
55
     *
56
     * @return void
57
     */
58 View Code Duplication
    public function showOnePost($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...
59
    {
60
        $data = $this->di->get("comment")->showOnePost($id);
61
62
        $this->di->get("view")->add("comment/post", ["content" => $data]);
63
        $this->di->get("pageRender")->renderPage(["title" => "Post id ".$id]);
64
    }
65
66
    /**
67
     * Edit post
68
     *
69
     * @return void
70
     */
71 View Code Duplication
    public function editPost($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...
72
    {
73
        $data = $this->di->get("comment")->editPost($id);
74
75
        $this->di->get("view")->add("comment/update_comment", ["content" => $data]);
76
        $this->di->get("pageRender")->renderPage(["title" => "Update comment"]);
77
    }
78
79
    /**
80
     * Edit post action
81
     *
82
     * @return void
83
     */
84
    public function editPostAction()
85
    {
86
        $this->di->get("view")->add("comment/update_comment_action");
87
        $this->di->get("pageRender")->renderPage(["title" => "Update comment action"]);
88
    }
89
90
    /**
91
     * Remove post
92
     *
93
     * @return void
94
     */
95
    public function removePost($id)
96
    {
97
        $this->di->get("comment")->removePost($id);
98
    }
99
}
100