Passed
Pull Request — master (#192)
by Alexander
04:59 queued 02:28
created

Hidden::generateInput()   A

Complexity

Conditions 4
Paths 2

Size

Total Lines 12
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 4.074

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 5
nc 2
nop 0
dl 0
loc 12
ccs 5
cts 6
cp 0.8333
crap 4.074
rs 10
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Form\Field;
6
7
use InvalidArgumentException;
8
use Yiisoft\Form\Field\Base\AbstractField;
9
use Yiisoft\Html\Html;
10
11
use function is_string;
12
13
final class Hidden extends AbstractField
14
{
15
    protected bool $useContainer = false;
16
    protected string $template = '{input}';
17
18 1
    protected function generateInput(): string
19
    {
20 1
        $value = $this->getAttributeValue();
21
22 1
        if (!is_string($value) && !is_numeric($value) && $value !== null) {
23
            throw new InvalidArgumentException('Hidden widget requires a string, numeric or null value.');
24
        }
25
26 1
        $tagAttributes = $this->getInputTagAttributes();
27
28
        /** @psalm-suppress MixedArgumentTypeCoercion */
29 1
        return Html::hiddenInput($this->getInputName(), $value, $tagAttributes)->render();
30
    }
31
}
32