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

Telephone   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
use Yiisoft\Html\Html;
16
17
use function is_string;
18
19
/**
20
 * @link https://html.spec.whatwg.org/multipage/input.html#telephone-state-(type=tel)
21
 */
22
final class Telephone extends AbstractField
23
{
24
    use MinMaxLengthTrait;
25
    use PatternTrait;
26
    use PlaceholderTrait;
27
    use ReadonlyTrait;
28
    use RequiredTrait;
29
    use SizeTrait;
30
31 1
    protected function generateInput(): string
32
    {
33 1
        $value = $this->getAttributeValue();
34
35 1
        if (!is_string($value) && $value !== null) {
36
            throw new InvalidArgumentException('Telephone widget must be a string or null value.');
37
        }
38
39 1
        $tagAttributes = $this->getInputTagAttributes();
40
41
        /** @psalm-suppress MixedArgumentTypeCoercion */
42 1
        return Html::input('tel', $this->getInputName(), $value)
43 1
            ->attributes($tagAttributes)
44 1
            ->render();
45
    }
46
}
47