Test Failed
Pull Request — master (#181)
by Wilmer
02:24
created

Hidden::run()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 17
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 8
c 1
b 0
f 0
nc 3
nop 0
dl 0
loc 17
ccs 9
cts 9
cp 1
crap 4
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Form\Widget;
6
7
use InvalidArgumentException;
8
use Yiisoft\Form\Widget\Attribute\InputAttributes;
9
use Yiisoft\Html\Tag\Input;
10
11
/**
12
 * The input element with a type attribute whose value is "hidden" represents a value that is not intended to be
13
 * examined or manipulated by the user.
14
 *
15
 * @link https://www.w3.org/TR/2012/WD-html-markup-20120329/input.hidden.html#input.hidden
16
 */
17
final class Hidden extends InputAttributes
18
{
19
    /**
20
     * Generates a hidden input tag for the given form attribute.
21
     *
22
     * @return string the generated input tag.
23
     */
24 4
    protected function run(): string
25
    {
26 4
        $attributes = $this->attributes;
27
28
        /** @link https://www.w3.org/TR/2012/WD-html-markup-20120329/input.hidden.html#input.hidden.attrs.value */
29 4
        $value = $attributes['value'] ?? $this->getAttributeValue();
30 4
        unset($attributes['value']);
31
32 4
<<<<<<< HEAD
0 ignored issues
show
Bug introduced by
A parse error occurred: Syntax error, unexpected T_SL on line 32 at column 0
Loading history...
33 2
        if (!is_string($value) && !is_numeric($value) && !is_null($value)) {
34
            throw new InvalidArgumentException('Hidden widget requires a string, numeric or null value.');
35
=======
36 2
        if (!is_string($value) && !is_numeric($value) && null !== $value) {
37 2
            throw new InvalidArgumentException('Hidden widget requires a string value.');
38
>>>>>>> 46a5b82f580d84b7c0f2725294a936bf67aedf39
39
        }
40 2
41
        if (!array_key_exists('name', $attributes)) {
42
            $attributes['name'] = $this->getInputId();
43
        }
44
45
        return Input::tag()->type('hidden')->attributes($attributes)->value($value === '' ? null : $value)->render();
46
    }
47
}
48