Hidden   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 16
ccs 6
cts 6
cp 1
rs 10
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A generateInput() 0 11 4
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Form\Field;
6
7
use InvalidArgumentException;
8
use Yiisoft\Form\Field\Base\InputField;
9
use Yiisoft\Html\Html;
10
11
use function is_string;
12
13
/**
14
 * Represents `<input>` element of type "hidden" are let web developers include data that cannot be seen or modified by
15
 * users when a form is submitted
16
 *
17
 * @link https://html.spec.whatwg.org/multipage/input.html#hidden-state-(type=hidden)
18
 * @link https://developer.mozilla.org/docs/Web/HTML/Element/input/hidden
19
 */
20
final class Hidden extends InputField
21
{
22
    protected bool $useContainer = false;
23
    protected string $template = '{input}';
24
25 7
    protected function generateInput(): string
26
    {
27 7
        $value = $this->getValue();
28
29 7
        if (!is_string($value) && !is_numeric($value) && $value !== null) {
30 1
            throw new InvalidArgumentException('Hidden widget requires a string, numeric or null value.');
31
        }
32
33 6
        $inputAttributes = $this->getInputAttributes();
34
35 6
        return Html::hiddenInput($this->getName(), $value, $inputAttributes)->render();
36
    }
37
}
38