FormModelSearchWidget::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 10
nc 1
nop 1
dl 0
loc 16
ccs 0
cts 9
cp 0
crap 2
rs 9.9332
c 0
b 0
f 0
1
<?php
2
3
namespace Anax\HTMLForm;
4
5
use Psr\Container\ContainerInterface;
6
7
/**
8
 * Example of FormModel implementation.
9
 */
10
class FormModelSearchWidget 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
                //"wrapper-element" => "div",
25
            ],
26
            [
27
                "search" => [
28
                    "type"        => "search-widget",
29
                    "description" => "Here you can place a description.",
30
                    "placeholder" => "Here is a placeholder",
31
                    "label"       => "Search",
32
                    "callback"    => [$this, "callbackSubmit"],
33
                ]
34
            ]
35
        );
36
    }
37
38
39
40
    /**
41
     * Callback for submit-button which should return true if it could
42
     * carry out its work and false if something failed.
43
     *
44
     * @return boolean true if okey, false if something went wrong.
45
     */
46
    public function callbackSubmit()
47
    {
48
        $this->form->addOutput(
49
            "Searchstring is: "
50
            . $this->form->value("search")
51
            . "</br>"
52
        );
53
54
        // Remember values during resubmit, for sake of the example
55
        $this->form->rememberValues();
56
57
        return true;
58
    }
59
}
60