CreateCommentsForm   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 84
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 39
c 1
b 0
f 0
dl 0
loc 84
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A callbackSubmit() 0 23 1
A __construct() 0 39 1
1
<?php
2
3
namespace Alfs18\User\HTMLForm;
4
5
use Alfs18\User\Comments;
6
use Anax\HTMLForm\FormModel;
7
use Psr\Container\ContainerInterface;
8
9
/**
10
 * Example of FormModel implementation.
11
 */
12
class CreateCommentsForm extends FormModel
13
{
14
    /**
15
     * Constructor injects with DI container.
16
     *
17
     * @param Psr\Container\ContainerInterface $di a service container
0 ignored issues
show
Bug introduced by
The type Alfs18\User\HTMLForm\Psr...iner\ContainerInterface was not found. Did you mean Psr\Container\ContainerInterface? If so, make sure to prefix the type with \.
Loading history...
18
     * @param $acronym the name of the one who posted the comment.
19
     * @param $qId the questionId.
0 ignored issues
show
Bug introduced by
The type Alfs18\User\HTMLForm\the was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
20
     */
21
    public function __construct(ContainerInterface $di, $acronym, $qId)
22
    {
23
        parent::__construct($di);
24
        $this->form->create(
25
            [
26
                "id" => __CLASS__,
27
                // "legend" => "Kommentera",
28
                "class" => "comments",
29
            ],
30
            [
31
                "acronym" => [
32
                    "type"  => "hidden",
33
                    "value" => $acronym,
34
                ],
35
36
                "questionId" => [
37
                    "type"  => "hidden",
38
                    "value" => $qId,
39
                ],
40
41
                "created" => [
42
                    "type"  => "hidden",
43
                    "value" => date("d M Y, H:i"),
44
                ],
45
46
                "comment" => [
47
                    "type"  => "text",
48
                    "placeholder" => "Kommentera",
49
                ],
50
51
                "points" => [
52
                    "type"  => "hidden",
53
                    "value" => 0,
54
                ],
55
56
                "submit" => [
57
                    "type" => "submit",
58
                    "value" => "Skicka",
59
                    "callback" => [$this, "callbackSubmit"]
60
                ],
61
            ]
62
        );
63
    }
64
65
66
67
    /**
68
     * Callback for submit-button which should return true if it could
69
     * carry out its work and false if something failed.
70
     *
71
     * @return boolean true if okey, false if something went wrong.
72
     */
73
    public function callbackSubmit()
74
    {
75
        // Get values from the submitted form
76
        $acronym = $this->form->value("acronym");
77
        $qId = $this->form->value("questionId");
78
        $created = $this->form->value("created");
79
        $comment = $this->form->value("comment");
80
        $points = $this->form->value("points");
81
82
        // Save to database
83
        $res = new Comments();
84
        $res->setDb($this->di->get("dbqb"));
85
        $res->acronym = $acronym;
86
        $res->questionId = $qId;
87
        $res->created = $created;
88
        $res->comment = $res->changeCharacter($comment);
89
        $res->points = intval($points);
90
        // var_dump("Hello");
91
        // var_dump($res);
92
        $res->saveComment($this->di);
93
94
        $this->form->addOutput("Comment was created.");
95
        return true;
96
    }
97
}
98