Passed
Push — master ( ceaca3...579756 )
by Kevin Olguin
01:46
created

Comment2Controller   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 154
Duplicated Lines 56.49 %

Coupling/Cohesion

Components 1
Dependencies 7

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 7
dl 87
loc 154
ccs 91
cts 91
cp 1
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A comment2Create() 29 29 2
A setUser() 0 21 1
A getIndex() 0 20 1
A comment2Update() 29 29 2
A comment2Delete() 29 29 2

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 Kifekenny\Comment;
4
5
use \Anax\Configure\ConfigureInterface;
6
use \Anax\Configure\ConfigureTrait;
7
use \Anax\DI\InjectionAwareInterface;
8
use \Anax\DI\InjectionAwareTrait;
9
use \Kifekenny\Comment\Comment;
10
use \Kifekenny\Comment\HTMLForm\Com2Create;
11
use \Kifekenny\Comment\HTMLForm\Com2Update;
12
use \Kifekenny\Comment\HTMLForm\Com2Delete;
13
use \Kifekenny\Comment\HTMLForm\Com2Session;
14
15
/**
16
 * A controller class.
17
 */
18
class Comment2Controller 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 1
    public function getIndex()
40
    {
41 1
        $title      = "View | Comments";
42 1
        $view       = $this->di->get("view");
43 1
        $pageRender = $this->di->get("pageRender");
44 1
        $comment2   = new Comment();
45 1
        $comment2->setDb($this->di->get("db"));
46
47
        $data = [
48 1
            "items" => $comment2->findAll(),
49 1
        ];
50
51 1
        $view->add("incl/header", ["title" => ["Book", "css/style.css"]]);
52 1
        $view->add("incl/side-bar1");
53 1
        $view->add("comment/viewAll", $data);
54 1
        $view->add("incl/side-bar2");
55 1
        $view->add("incl/footer");
56
57 1
        $pageRender->renderPage(["title" => $title]);
58 1
    }
59
60 1 View Code Duplication
    public function comment2Create()
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 1
        $session = $this->di->get("session");
63 1
        $userId = $session->get("user_id");
64
65 1
        if (!$userId) {
66 1
            $this->di->get("response")->redirect("");
67 1
        }
68
69 1
        $title      = "Create | Comment";
70 1
        $view       = $this->di->get("view");
71 1
        $pageRender = $this->di->get("pageRender");
72 1
        $comment2   = new Com2Create($this->di);
73
74 1
        $comment2->check();
75
76
        $data = [
77 1
            "form" => $comment2->getHTML(),
78 1
        ];
79
80
81 1
        $view->add("incl/header", ["title" => ["Book", "../css/style.css"]]);
82 1
        $view->add("incl/side-bar1");
83 1
        $view->add("comment/create", $data);
84 1
        $view->add("incl/side-bar2");
85 1
        $view->add("incl/footer");
86
87 1
        $pageRender->renderPage(["title" => $title]);
88 1
    }
89
90 1 View Code Duplication
    public function comment2Update($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...
91
    {
92 1
        $session = $this->di->get("session");
93 1
        $userId = $session->get("user_id");
94
95 1
        if (!$userId) {
96 1
            $this->di->get("response")->redirect("");
97 1
        }
98
99 1
        $title      = "Create | Comment";
100 1
        $view       = $this->di->get("view");
101 1
        $pageRender = $this->di->get("pageRender");
102 1
        $comment2   = new Com2Update($this->di, $id);
103
104 1
        $comment2->check();
105
106 1
        $data = [
107 1
            "form" => $comment2->getHTML(),
108 1
        ];
109
110
111 1
        $view->add("incl/header", ["title" => ["Book", "../../css/style.css"]]);
112 1
        $view->add("incl/side-bar1");
113 1
        $view->add("comment/create", $data);
114 1
        $view->add("incl/side-bar2");
115 1
        $view->add("incl/footer");
116
117 1
        $pageRender->renderPage(["title" => $title]);
118 1
    }
119
120 1 View Code Duplication
    public function comment2Delete($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...
121
    {
122 1
        $session = $this->di->get("session");
123 1
        $userId = $session->get("user_id");
124
125 1
        if (!$userId) {
126 1
            $this->di->get("response")->redirect("");
127 1
        }
128
129 1
        $title      = "Delete | Comment";
130 1
        $view       = $this->di->get("view");
131 1
        $pageRender = $this->di->get("pageRender");
132 1
        $comment2   = new Com2Delete($this->di, $id);
133
134 1
        $comment2->check();
135
136
        $data = [
137 1
            "form" => $comment2->getHTML(),
138 1
        ];
139
140
141 1
        $view->add("incl/header", ["title" => ["Book", "../../css/style.css"]]);
142 1
        $view->add("incl/side-bar1");
143 1
        $view->add("comment/create", $data);
144 1
        $view->add("incl/side-bar2");
145 1
        $view->add("incl/footer");
146
147 1
        $pageRender->renderPage(["title" => $title]);
148 1
    }
149
150 1
    public function setUser()
151
    {
152 1
        $title      = "Set | Session";
153 1
        $view       = $this->di->get("view");
154 1
        $pageRender = $this->di->get("pageRender");
155 1
        $comment2   = new Com2Session($this->di);
156
157 1
        $comment2->check();
158
159
        $data = [
160 1
            "form" => $comment2->getHTML(),
161 1
        ];
162
163 1
        $view->add("incl/header", ["title" => ["Book", "../../css/style.css"]]);
164 1
        $view->add("incl/side-bar1");
165 1
        $view->add("comment/default", $data);
166 1
        $view->add("incl/side-bar2");
167 1
        $view->add("incl/footer");
168
169 1
        $pageRender->renderPage(["title" => $title]);
170 1
    }
171
}
172