FormModelElementsAll   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 243
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 148
dl 0
loc 243
ccs 0
cts 24
cp 0
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A callbackSubmit() 0 38 3
B __construct() 0 185 1
1
<?php
2
3
namespace Anax\HTMLForm;
4
5
use Psr\Container\ContainerInterface;
6
7
/**
8
 * Example of FormModel implementation.
9
 */
10
class FormModelElementsAll 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(DIInterface $di)
0 ignored issues
show
Bug introduced by
The type Anax\HTMLForm\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...
18
    {
19
        parent::__construct($di);
20
        $this->form->create(
21
            [
22
                "id" => __CLASS__,
23
                "legend" => "Legend",
24
            ],
25
            [
26
                "text" => [
27
                    "type"        => "text",
28
                    "description" => "Here you can place a description.",
29
                    "placeholder" => "Here is a placeholder",
30
                ],
31
                        
32
                "password" => [
33
                    "type"        => "password",
34
                    "description" => "Here you can place a description.",
35
                    "placeholder" => "Here is a placeholder",
36
                ],
37
38
                "hidden" => [
39
                    "type"        => "hidden",
40
                    "value"       => "secret value",
41
                ],
42
43
                "file" => [
44
                    "type"        => "file",
45
                    "description" => "Here you can place a description.",
46
                ],
47
48
                "textarea" => [
49
                    "type"        => "textarea",
50
                    "description" => "Here you can place a description.",
51
                    "placeholder" => "Here is a placeholder",
52
                ],
53
54
                "radio" => [
55
                    "type"        => "radio",
56
                    "label"       => "What is your preferred choice of fruite?",
57
                    "description" => "Here you can place a description.",
58
                    "values"      => [
59
                        "tomato",
60
                        "potato",
61
                        "apple",
62
                        "pear",
63
                        "banana"
64
                    ],
65
                    "checked"     => "potato",
66
                ],
67
68
                "checkbox" => [
69
                    "type"        => "checkbox",
70
                    "description" => "Here you can place a description.",
71
                ],
72
73
                "select" => [
74
                    "type"        => "select",
75
                    "label"       => "Select your fruite:",
76
                    "description" => "Here you can place a description.",
77
                    "options"     => [
78
                        "tomato" => "tomato",
79
                        "potato" => "potato",
80
                        "apple"  => "apple",
81
                        "pear"   => "pear",
82
                        "banana" => "banana",
83
                    ],
84
                    "value"    => "potato",
85
                ],
86
87
                "selectm" => [
88
                    "type"        => "select-multiple",
89
                    "label"       => "Select one or more fruite:",
90
                    "description" => "Here you can place a description.",
91
                    "size"        => 6,
92
                    "options"     => [
93
                        "tomato" => "tomato",
94
                        "potato" => "potato",
95
                        "apple"  => "apple",
96
                        "pear"   => "pear",
97
                        "banana" => "banana",
98
                    ],
99
                    "checked"   => ["potato", "pear"],
100
                ],
101
102
                "color" => [
103
                    "type"        => "color",
104
                    "description" => "Here you can place a description.",
105
                    "placeholder" => "Here is a placeholder",
106
                ],
107
108
                "date" => [
109
                    "type"        => "date",
110
                    "description" => "Here you can place a description.",
111
                    "placeholder" => "Here is a placeholder",
112
                ],
113
114
                "datetime" => [
115
                    "type"        => "datetime",
116
                    "description" => "Here you can place a description.",
117
                    "placeholder" => "Here is a placeholder",
118
                ],
119
120
                "datetime-local" => [
121
                    "type"        => "datetime-local",
122
                    "description" => "Here you can place a description.",
123
                    "placeholder" => "Here is a placeholder",
124
                ],
125
126
                "time" => [
127
                    "type"        => "time",
128
                    "description" => "Here you can place a description.",
129
                    "placeholder" => "Here is a placeholder",
130
                ],
131
132
                "week" => [
133
                    "type"        => "week",
134
                    "description" => "Here you can place a description.",
135
                    "placeholder" => "Here is a placeholder",
136
                ],
137
138
                "month" => [
139
                    "type"        => "month",
140
                    "description" => "Here you can place a description.",
141
                    "placeholder" => "Here is a placeholder",
142
                ],
143
144
                "number" => [
145
                    "type"        => "number",
146
                    "description" => "Here you can place a description.",
147
                    "placeholder" => "Here is a placeholder",
148
                ],
149
150
                "range" => [
151
                    "type"        => "range",
152
                    "description" => "Here you can place a description.",
153
                    "placeholder" => "Here is a placeholder",
154
                    "value"       => 42,
155
                    "min"         => 0,
156
                    "max"         => 100,
157
                    "step"        => 2,
158
                ],
159
160
                "search" => [
161
                    "type"        => "search",
162
                    "label"       => "Search:",
163
                    "description" => "Here you can place a description.",
164
                    "placeholder" => "Here is a placeholder",
165
                ],
166
167
                "tel" => [
168
                    "type"        => "tel",
169
                    "description" => "Here you can place a description.",
170
                    "placeholder" => "Here is a placeholder",
171
                ],
172
173
                "email" => [
174
                    "type"        => "email",
175
                    "description" => "Here you can place a description.",
176
                    "placeholder" => "Here is a placeholder",
177
                ],
178
179
                "url" => [
180
                    "type"        => "url",
181
                    "description" => "Here you can place a description.",
182
                    "placeholder" => "Here is a placeholder",
183
                ],
184
185
                "file-multiple" => [
186
                    "type"        => "file-multiple",
187
                    "description" => "Here you can place a description.",
188
                ],
189
190
                "reset" => [
191
                    "type"      => "reset",
192
                ],
193
194
                "button" => [
195
                    "type"      => "button",
196
                ],
197
198
                "submit" => [
199
                    "type" => "submit",
200
                    "value" => "Submit",
201
                    "callback" => [$this, "callbackSubmit"]
202
                ],
203
            ]
204
        );
205
    }
206
207
208
209
    /**
210
     * Callback for submit-button which should return true if it could
211
     * carry out its work and false if something failed.
212
     *
213
     * @return boolean true if okey, false if something went wrong.
214
     */
215
    public function callbackSubmit()
216
    {
217
        // These return a single value
218
        // Type checkbox returns true if checked
219
        $elements = [
220
            // HTML401.
221
            "text", "password", "hidden", "file", "textarea", "select",
222
            "radio", "checkbox",
223
            // HTML5
224
            "color", "date", "datetime", "datetime-local", "time",
225
            "week", "month", "number", "range", "search", "tel",
226
            "email", "url", "file-multiple",
227
        ];
228
        foreach ($elements as $name) {
229
            $this->form->addOutput(
230
                "$name has value: "
231
                . $this->form->value($name)
232
                . "</br>"
233
            );
234
        }
235
236
        // Select multiple returns an array
237
        $elements = [
238
            "selectm",
239
        ];
240
        foreach ($elements as $name) {
241
            $this->form->addOutput(
242
                "$name has value: "
243
                . implode($this->form->value($name), ", ")
0 ignored issues
show
Bug introduced by
', ' of type string is incompatible with the type array expected by parameter $pieces of implode(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

243
                . implode($this->form->value($name), /** @scrutinizer ignore-type */ ", ")
Loading history...
244
                . "</br>"
245
            );
246
        }
247
248
        // Remember values during resubmit, useful when failing (retunr false)
249
        // and asking the user to resubmit the form.
250
        $this->form->rememberValues();
251
252
        return true;
253
    }
254
}
255