Passed
Pull Request — master (#192)
by Alexander
03:02
created

Hidden   A

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
 * The input element with a type attribute whose value is "hidden" represents a value that is not intended to be
15
 * examined or manipulated by the user.
16
 *
17
 * @link https://html.spec.whatwg.org/multipage/input.html#hidden-state-(type=hidden)
18
 */
19
final class Hidden extends InputField
20
{
21
    protected bool $useContainer = false;
22
    protected string $template = '{input}';
23
24 4
    protected function generateInput(): string
25
    {
26 4
        $value = $this->getAttributeValue();
27
28 4
        if (!is_string($value) && !is_numeric($value) && $value !== null) {
29 1
            throw new InvalidArgumentException('Hidden widget requires a string, numeric or null value.');
30
        }
31
32 3
        $tagAttributes = $this->getInputTagAttributes();
33
34 3
        return Html::hiddenInput($this->getInputName(), $value, $tagAttributes)->render();
35
    }
36
}
37