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

Url::generateInput()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3.0175

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 7
nc 2
nop 0
dl 0
loc 14
ccs 7
cts 8
cp 0.875
crap 3.0175
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\Form\Field\Base\MinMaxLengthTrait;
10
use Yiisoft\Form\Field\Base\PatternTrait;
11
use Yiisoft\Form\Field\Base\PlaceholderTrait;
12
use Yiisoft\Form\Field\Base\ReadonlyTrait;
13
use Yiisoft\Form\Field\Base\RequiredTrait;
14
use Yiisoft\Form\Field\Base\SizeTrait;
15
16
use Yiisoft\Html\Html;
17
18
use function is_string;
19
20
/**
21
 * @link https://html.spec.whatwg.org/multipage/input.html#url-state-(type=url)
22
 */
23
final class Url extends AbstractField
24
{
25
    use MinMaxLengthTrait;
26
    use PatternTrait;
27
    use PlaceholderTrait;
28
    use ReadonlyTrait;
29
    use RequiredTrait;
30
    use SizeTrait;
31
32 1
    protected function generateInput(): string
33
    {
34 1
        $value = $this->getAttributeValue();
35
36 1
        if (!is_string($value) && $value !== null) {
37
            throw new InvalidArgumentException('URL widget must be a string or null value.');
38
        }
39
40 1
        $tagAttributes = $this->getInputTagAttributes();
41
42
        /** @psalm-suppress MixedArgumentTypeCoercion */
43 1
        return Html::input('url', $this->getInputName(), $value)
44 1
            ->attributes($tagAttributes)
45 1
            ->render();
46
    }
47
}
48