Completed
Push — master ( 66b618...d2e9dc )
by Gunvor
01:50
created

CommController::toRender()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 0
cts 7
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 3
crap 2
1
<?php
2
3
namespace Anax\Comments;
4
5
use \Anax\Configure\ConfigureInterface;
6
use \Anax\Configure\ConfigureTrait;
7
use \Anax\DI\InjectionAwareInterface;
8
use \Anax\DI\InjectionAwareTrait;
9
use \Anax\Comments\HTMLForm\CreateCommForm;
10
use \Anax\Comments\HTMLForm\UpdateCommForm;
11
use \Anax\Comments\HTMLForm\DeleteCommForm;
12
use \Anax\Comments\HTMLForm\AdminDeleteCommForm;
13
use \Anax\Comments\ShowOneService;
14
use \Anax\Comments\ShowAllService;
15
16
/**
17
 * A controller class.
18
 */
19
class CommController implements
20
    ConfigureInterface,
21
    InjectionAwareInterface
22
{
23
    use ConfigureTrait,
24
        InjectionAwareTrait;
25
26
27
    /**
28
     * Sends data to view
29
     *
30
     * @param string $title
31
     * @param string $crud, path to view
0 ignored issues
show
Bug introduced by
There is no parameter named $crud,. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
32
     * @param array $data, htmlcontent to view
0 ignored issues
show
Bug introduced by
There is no parameter named $data,. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
33
     */
34
    public function toRender($title, $crud, $data)
35
    {
36
        $view       = $this->di->get("view");
37
        $pageRender = $this->di->get("pageRender");
38
        $view->add($crud, $data);
39
        $tempfix = "";
40
        $pageRender->renderPage($tempfix, ["title" => $title]);
41
    }
42
43
44
    /**
45
     * Show all items.
46
     *
47
     * @return void
48
     */
49 View Code Duplication
    public function getIndex()
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...
50
    {
51
        $title      = "Inlägg";
52
53
        $text = new ShowAllService($this->di);
54
55
        $data = [
56
            "items" => $text->getHTML(),
57
        ];
58
59
        $crud = "comm/crud/front";
60
        $this->toRender($title, $crud, $data);
61
    }
62
63
64
65
    /**
66
     * Handler with form to create a new item.
67
     *
68
     * @return void
69
     */
70 View Code Duplication
    public function getPostCreateItem($id = null)
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...
71
    {
72
        $title      = "Skriv ett inlägg";
73
74
        $session = $this->di->get("session");
75
        $sess = $session->get("user");
76
77
        if ($sess) {
78
            $form       = new CreateCommForm($this->di, $sess['id'], $id);
79
            $form->check();
80
81
            $data = [
82
                "form" => $form->getHTML(),
83
            ];
84
        } else {
85
            $data = [
86
                "form" => "Enbart för inloggade. Sorry!",
87
            ];
88
        }
89
90
        $crud = "comm/crud/create";
91
        $this->toRender($title, $crud, $data);
92
    }
93
94
95
    /**
96
     * Handler with form to delete an item.
97
     *
98
     * @return void
99
     */
100 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...
101
    {
102
        $title      = "Ta bort ett inlägg";
103
104
        $session = $this->di->get("session");
105
        $sess = $session->get("user");
106
107
        if ($sess) {
108
            $form       = new DeleteCommForm($this->di, $id);
109
            $form->check();
110
111
            $data = [
112
                "form" => $form->getHTML(),
113
            ];
114
        } else {
115
            $data = [
116
                "form" => "Enbart för inloggade. Sorry!",
117
            ];
118
        }
119
120
        $crud = "comm/crud/delete";
121
        $this->toRender($title, $crud, $data);
122
    }
123
124
125
126
    /**
127
     * Handler with form to update an item.
128
     *
129
     * @return void
130
     */
131 View Code Duplication
    public function getPostAdminDeleteItem()
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...
132
    {
133
        $title      = "Ta bort text";
134
        $form       = new AdminDeleteCommForm($this->di);
135
136
        $form->check();
137
138
        $data = [
139
            "form" => $form->getHTML(),
140
        ];
141
142
        $crud = "comm/crud/admindelete";
143
        $this->toRender($title, $crud, $data);
144
    }
145
146
147
148
    /**
149
     * Handler with form to update an item.
150
     *
151
     * @return void
152
     */
153 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...
154
    {
155
        $title      = "Uppdatera ditt inlägg";
156
157
        $session = $this->di->get("session");
158
        $sess = $session->get("user");
159
160
        if ($sess) {
161
            $form       = new UpdateCommForm($this->di, $id, $sess['id']);
162
            $form->check();
163
164
            $data = [
165
                "form" => $form->getHTML(),
166
            ];
167
        } else {
168
            $data = [
169
                "form" => "Enbart för inloggade. Sorry!",
170
            ];
171
        }
172
173
        $crud = "comm/crud/update";
174
        $this->toRender($title, $crud, $data);
175
    }
176
177
178
    /**
179
     * Handler with form to just show an item.
180
     *
181
     * @return void
182
     */
183 View Code Duplication
    public function getPostShow($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...
184
    {
185
        $title      = "Inlägg";
186
        $text       = new ShowOneService($this->di, $id);
187
188
        $data = [
189
            "items" => $text->getHTML(),
190
        ];
191
192
        $crud = "comm/crud/view-one";
193
        $this->toRender($title, $crud, $data);
194
    }
195
}
196