Com2Session::callbackSubmit()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 18
ccs 0
cts 11
cp 0
rs 9.6666
c 0
b 0
f 0
cc 2
nc 2
nop 0
crap 6
1
<?php
2
3
// namespace AnaxSERHTMLFORM;
4
namespace Kifekenny\Comment\HTMLForm;
5
6
use \Anax\HTMLForm\FormModel;
7
use \Anax\DI\DIInterface;
8
use \Kifekenny\Comment\Comment;
9
10
/**
11
 * Example of FormModel implementation.
12
 */
13
class Com2Session extends FormModel
14
{
15
    /**
16
     * Constructor injects with DI container.
17
     *
18
     * @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...
19
     */
20 2
    public function __construct(DIInterface $dis)
21
    {
22 2
        parent::__construct($dis);
23 2
        $this->form->create(
24
            [
25 2
                "id" => __CLASS__,
26 2
                "legend" => "Set session",
27 2
            ],
28
            [
29
                "mail" => [
30 2
                    "type"        => "text",
31 2
                    "validation"  => ["not_empty"],
32 2
                ],
33
                "submit" => [
34 2
                    "type" => "submit",
35 2
                    "value" => "Set session",
36 2
                    "callback" => [$this, "callbackSubmit"]
37 2
                ],
38
            ]
39 2
        );
40 2
    }
41
42
43
44
    /**
45
     * Callback for submit-button which should return true if it could
46
     * carry out its work and false if something failed.
47
     *
48
     * @return boolean true if okey, false if something went wrong.
49
     */
50
    public function callbackSubmit()
51
    {
52
         // Get values from the submitted form
53
        $mail = $this->form->value("mail");
54
55
        $session = $this->di->get("session");
56
57
        if (!$mail) {
58
            $this->form->addOutput("Can't be empty");
59
            return false;
60
        }
61
        $session->set("user_id", 1);
62
        $session->set("user_mail", $mail);
63
        $session->set("user_name", $mail);
64
65
        $this->form->addOutput("User was created.");
66
        return true;
67
    }
68
}
69