Com2Create   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 73.68%

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 3
dl 0
loc 66
ccs 28
cts 38
cp 0.7368
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 38 1
A callbackSubmit() 0 12 1
1
<?php
2
3
namespace Kifekenny\Comment\HTMLForm;
4
5
use \Anax\HTMLForm\FormModel;
6
use \Anax\DI\DIInterface;
7
use \Kifekenny\Comment\Comment;
8
9
/**
10
 * Form to create an item.
11
 */
12
class Com2Create extends FormModel
13
{
14
    /**
15
     * Constructor injects with DI container.
16
     *
17
     * @param Anax\DI\DIInterface $di a service container
0 ignored issues
show
Bug introduced by
There is no parameter named $di. 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...
18
     */
19 2
    public function __construct(DIInterface $dis)
20
    {
21 2
        parent::__construct($dis);
22 2
        $session = $this->di->get("session");
23 2
        $this->form->create(
24
            [
25 2
                "id" => __CLASS__,
26 2
                "legend" => "Add Comment",
27 2
            ],
28
            [
29 1
                "userId" => [
30 2
                    "type" => "hidden",
31 2
                    "validation" => ["not_empty"],
32 2
                    "value" => $session->get("user_id"),
33 2
                ],
34
                "Mail" => [
35 2
                    "type" => "text",
36 2
                    "readonly" => true,
37 2
                    "value" => $session->get("user_mail"),
38 2
                ],
39
                "Title" => [
40 2
                    "type" => "text",
41 2
                    "validation" => ["not_empty"],
42 2
                ],
43
44
                "Content" => [
45 2
                    "type" => "textarea",
46 2
                    "validation" => ["not_empty"],
47 2
                ],
48
49
                "submit" => [
50 2
                    "type" => "submit",
51 2
                    "value" => "Submit Comment",
52 2
                    "callback" => [$this, "callbackSubmit"]
53 2
                ],
54
            ]
55 2
        );
56 2
    }
57
58
59
    /**
60
     * Callback for submit-button which should return true if it could
61
     * carry out its work and false if something failed.
62
     *
63
     * @return boolean true if okey, false if something went wrong.
64
     */
65
    public function callbackSubmit()
66
    {
67
        $comment = new Comment();
68
        $comment->setDb($this->di->get("db"));
69
        $comment->title      = $this->form->value("Title");
70
        $comment->content    = $this->form->value("Content");
71
        $comment->userMail  = $this->form->value("Mail");
72
        $comment->userId    = $this->form->value("userId");
73
        // $comment->user_id
74
        $comment->save();
75
        $this->di->get("response")->redirect("");
76
    }
77
}
78