CommentController   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 118
Duplicated Lines 30.51 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 7
dl 36
loc 118
c 0
b 0
f 0
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getIndex() 0 19 1
A getPostCreateItem() 0 17 1
A getPostDeleteItem() 18 18 1
A getPostUpdateItem() 18 18 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 Vibe\Comment;
4
5
use \Anax\Configure\ConfigureInterface;
6
use \Anax\Configure\ConfigureTrait;
7
use \Anax\DI\InjectionAwareInterface;
8
use \Anax\DI\InjectionAwareTrait;
9
use \Vibe\Comment\HTMLForm\CreateForm;
10
use \Vibe\Comment\HTMLForm\EditForm;
11
use \Vibe\Comment\HTMLForm\DeleteForm;
12
use \Vibe\Comment\HTMLForm\UpdateForm;
13
use \Vibe\Gravatar\Gravatar;
14
15
/**
16
 * A controller class.
17
 */
18
class CommentController implements
19
    ConfigureInterface,
20
    InjectionAwareInterface
21
{
22
    use ConfigureTrait,
23
        InjectionAwareTrait;
24
25
26
27
    /**
28
     * @var $data description
29
     */
30
    //private $data;
31
32
33
34
    /**
35
     * Show all items.
36
     *
37
     * @return void
38
     */
39
    public function getIndex()
40
    {
41
        $title      = "A collection of items";
42
        $view       = $this->di->get("view");
43
        $pageRender = $this->di->get("pageRender");
44
        $comment = new Comment();
45
        $gravatar = new Gravatar();
46
        $comment->setDb($this->di->get("database"));
47
48
        $data = [
49
            "allComments" => $comment->findAll(),
50
            "gravatar" => $gravatar,
51
            "username" => $this->di->get("session")->get("username"),
52
        ];
53
54
        $view->add("comment/view", $data);
55
56
        $pageRender->renderPage(["title" => $title]);
57
    }
58
59
60
61
    /**
62
     * Handler with form to create a new item.
63
     *
64
     * @return void
65
     */
66
    public function getPostCreateItem()
67
    {
68
        $title      = "Create a item";
69
        $view       = $this->di->get("view");
70
        $pageRender = $this->di->get("pageRender");
71
        $form       = new CreateForm($this->di);
72
73
        $form->check();
74
75
        $data = [
76
            "form" => $form->getHTML(),
77
        ];
78
79
        $view->add("comment/create", $data);
80
81
        $pageRender->renderPage(["title" => $title]);
82
    }
83
84
85
86
    /**
87
     * Handler with form to delete an item.
88
     *
89
     * @return void
90
     */
91 View Code Duplication
    public function getPostDeleteItem()
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...
92
    {
93
        $title      = "Delete an item";
94
        $view       = $this->di->get("view");
95
        $pageRender = $this->di->get("pageRender");
96
        $userId    = $this->di->get("session")->get("userId");
97
        $form       = new DeleteForm($this->di, $userId);
98
99
        $form->check();
100
101
        $data = [
102
            "form" => $form->getHTML(),
103
        ];
104
105
        $view->add("comment/delete", $data);
106
107
        $pageRender->renderPage(["title" => $title]);
108
    }
109
110
111
112
    /**
113
     * Handler with form to update an item.
114
     *
115
     * @return void
116
     */
117 View Code Duplication
    public function getPostUpdateItem($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...
118
    {
119
        $title      = "Update an item";
120
        $view       = $this->di->get("view");
121
        $pageRender = $this->di->get("pageRender");
122
        $userId    = $this->di->get("session")->get("userId");
123
        $form       = new UpdateForm($this->di, $id, $userId);
124
125
        $form->check();
126
127
        $data = [
128
            "form" => $form->getHTML(),
129
        ];
130
131
        $view->add("comment/update", $data);
132
133
        $pageRender->renderPage(["title" => $title]);
134
    }
135
}
136