FormModelValidateNotEmpty   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 16
dl 0
loc 47
ccs 0
cts 13
cp 0
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 19 1
A callbackSubmit() 0 8 1
1
<?php
2
3
namespace Anax\HTMLForm;
4
5
use Psr\Container\ContainerInterface;
6
7
/**
8
 * Example of FormModel implementation.
9
 */
10
class FormModelValidateNotEmpty extends FormModel
11
{
12
    /**
13
     * Constructor injects with DI container.
14
     *
15
     * @param Anax\DI\DIInterface $di a service container
0 ignored issues
show
Bug introduced by
The type Anax\HTMLForm\Anax\DI\DIInterface 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...
16
     */
17
    public function __construct(ContainerInterface $di)
18
    {
19
        parent::__construct($di);
20
        $this->form->create(
21
            [
22
                "id" => __CLASS__,
23
                "legend" => "Legend",
24
            ],
25
            [
26
                "text" => [
27
                    "type" =>"text",
28
                    "label" => "Text, not empty (as input type=text)",
29
                    "validation" => ["not_empty"],
30
                ],
31
32
                "submit" => [
33
                    "type" => "submit",
34
                    "value" => "Submit",
35
                    "callback" => [$this, "callbackSubmit"]
36
                ],
37
            ]
38
        );
39
    }
40
41
42
43
    /**
44
     * Callback for submit-button which should return true if it could
45
     * carry out its work and false if something failed.
46
     *
47
     * @return boolean true if okey, false if something went wrong.
48
     */
49
    public function callbackSubmit()
50
    {
51
        $this->form->addOutput("Validation passes.");
52
53
        // Remember values during resubmit, for sake of the example
54
        $this->form->rememberValues();
55
56
        return true;
57
    }
58
}
59