CreateCommentForm   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 48.48%

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 4
dl 0
loc 68
ccs 16
cts 33
cp 0.4848
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
B callbackSubmit() 0 25 1
B __construct() 0 28 1
1
<?php
2
3
namespace Radchasay\Comment\HTMLForm;
4
5
use \Anax\HTMLForm\FormModel;
6
use \Anax\DI\DIInterface;
7
use \Radchasay\Comment\Comment;
8
use \Radchasay\User\User;
9
10
/**
11
 * Example of FormModel implementation.
12
 */
13
class CreateCommentForm extends FormModel
14
{
15
    /**
16
     * Constructor injects with DI container.
17
     *
18
     * @param Anax\DI\DIInterface $di a service container
19
     */
20 2
    public function __construct(DIInterface $di, $id)
21
    {
22 2
        parent::__construct($di);
23
24 2
        $this->form->create(
25
            [
26 2
                "id"     => __CLASS__,
27 2
                "legend" => "Create new comment",
28
                "class" => "createNewCommentForm"
29 2
            ],
30
            [
31
                    "text"    => [
32
                        "type"     => "textarea"
33 2
                    ],
34
35
                    "hidden" => [
36 2
                        "type"       => "hidden",
37 2
                        "value"      => $id,
38 2
                    ],
39
40
                    "submit" => [
41 2
                        "type"     => "submit",
42 2
                        "value"    => "Create comment",
43 2
                        "callback" => [$this, "callbackSubmit"],
44 2
                    ],
45
            ]
46 2
        );
47 2
    }
48
49
    /**
50
     * Callback for submit-button which should return true if it could
51
     * carry out its work and false if something failed.
52
     *
53
     * @return boolean true if okey, false if something went wrong.
54
     */
55
    public function callbackSubmit()
56
    {
57
        // Get values from the submitted form
58
59
        $comment = new Comment();
60
        $comment->setDB($this->di->get("db"));
61
        $data = $this->form->value("text");
62
        $text = $this->di->get("textfilter")->doFilter($data, ["shortcode", "markdown", "clickable", "bbcode"]);
63
        $comment->commenttext = $text;
64
        $comment->idpost = $this->form->value("hidden");
65
        $comment->postuser = $this->di->get("session")->get("email");
66
67
        $user = new User();
68
        $user->setDb($this->di->get("db"));
69
        $user->getInformation($comment->postuser);
70
        $user->points += 1;
0 ignored issues
show
Bug introduced by
The property points does not seem to exist in Radchasay\User\User.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
71
72
73
        $comment->save();
74
        $user->save();
75
76
        $url = $this->di->get("url")->create("comment/retrieve/$comment->idpost");
77
        $this->di->get("response")->redirect($url);
78
        return true;
79
    }
80
}
81