EditCommentForm::__construct()   B
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 37
Code Lines 23

Duplication

Lines 37
Ratio 100 %

Code Coverage

Tests 25
CRAP Score 1

Importance

Changes 0
Metric Value
dl 37
loc 37
ccs 25
cts 25
cp 1
rs 8.8571
c 0
b 0
f 0
cc 1
eloc 23
nc 1
nop 2
crap 1
1
<?php
2
3
namespace CJ\Comment\HTMLForm;
4
5
use \Anax\HTMLForm\FormModel;
6
use \Anax\DI\DIInterface;
7
use \CJ\Comment\Comment;
8
9
/**
10
 * Form to create an item.
11
 */
12
class EditCommentForm extends FormModel
13
{
14
    /**
15
     * Constructor injects with DI container.
16
     *
17
     * @param Anax\DI\DIInterface $di a service container
18
     */
19 2 View Code Duplication
    public function __construct(DIInterface $di, $comment)
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...
20
    {
21 2
        parent::__construct($di);
22 2
        $this->form->create(
23
            [
24 2
                "id" => __CLASS__,
25 2
            ],
26
            [
27
                "title" => [
28 2
                    "type" => "text",
29 2
                    "validation" => ["not_empty"],
30 2
                    "class" => "form-control",
31 2
                    "value" => "$comment->heading"
32 2
                ],
33
34
                "message" => [
35 2
                    "type" => "textarea",
36 2
                    "validation" => ["not_empty"],
37 2
                    "class" => "form-control",
38 2
                    "value" => "$comment->msg"
39 2
                ],
40
41
                "id" => [
42 2
                    "type" => "hidden",
43 2
                    "class" => "form-control",
44 2
                    "value" => "$comment->id"
45 2
                ],
46
47
                "submit" => [
48 2
                    "type" => "submit",
49 2
                    "value" => "Comment",
50 2
                    "callback" => [$this, "callbackSubmit"],
51
                    "class" => "btn btn-default"
52 2
                ],
53
            ]
54 2
        );
55 2
    }
56
57
58
59
    /**
60
     * @return boolean true if okey, false if something went wrong.
61
     */
62 1
    public function callbackSubmit()
63
    {
64 1
        $title = $this->form->value("title");
65 1
        $message = $this->form->value("message");
66 1
        $id = $this->form->value("id");
67
68 1
        $comment = new Comment();
69 1
        $comment->setDb($this->di->get("db"));
70
71 1
        $comment->find("id", $id);
72 1
        $comment->msg = $message;
73 1
        $comment->heading = $title;
74
75 1
        $comment->save();
76
77 1
        $this->form->addOutput("Kommentar uppdaterad");
78 1
        return true;
79
    }
80
}
81