FormModelCheckboxMultiple   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 18 1
A callbackSubmit() 0 16 1
1
<?php
2
3
namespace Alfs18\User\HTMLForm;
4
5
use Anax\HTMLForm\FormModel;
6
use Psr\Container\ContainerInterface;
7
8
/**
9
 * Example of FormModel implementation.
10
 */
11
class FormModelCheckboxMultiple extends FormModel
12
{
13
    /**
14
     * Constructor injects with DI container.
15
     *
16
     * @param Anax\DI\DIInterface $di a service container
0 ignored issues
show
Bug introduced by
The type Alfs18\User\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...
17
     */
18
    public function __construct(ContainerInterface $di, $tags)
19
    {
20
        parent::__construct($di);
21
        $this->form->create(
22
            [
23
                "id" => __CLASS__,
24
                "legend" => "Taggar"
25
            ],
26
            [
27
                "items" => [
28
                    "type"        => "checkbox-multiple",
29
                    "values"      => $tags,
30
                    // "values"      => ["tomato", "potato", "apple", "pear", "banana"],
31
                    // "checked"     => ["potato", "pear"],
32
                ],
33
                "submit" => [
34
                    "type"      => "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
        // Get the selected items as an array
52
        $items = $this->form->value("items");
53
54
        // Print output for sake of this example
55
        $this->form->addOutput(
56
            "<p>Selected items are: '"
57
            . implode(", ", $items)
58
            . "'."
59
        );
60
61
        // Remember values during resubmit, for sake of the example
62
        $this->form->rememberValues();
63
64
        return $items;
65
    }
66
}
67