CommentController   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 111
Duplicated Lines 45.95 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 6
dl 51
loc 111
c 0
b 0
f 0
ccs 0
cts 40
cp 0
rs 10

4 Methods

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