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

Url   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Test Coverage

Coverage 87.5%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
dl 0
loc 23
ccs 7
cts 8
cp 0.875
rs 10
c 1
b 0
f 0
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A generateInput() 0 14 3
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