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

Email::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 2
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 2
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
10
use Yiisoft\Form\Field\Base\MinMaxLengthTrait;
11
use Yiisoft\Form\Field\Base\MultipleTrait;
12
use Yiisoft\Form\Field\Base\PatternTrait;
13
use Yiisoft\Form\Field\Base\PlaceholderTrait;
14
use Yiisoft\Form\Field\Base\ReadonlyTrait;
15
use Yiisoft\Form\Field\Base\RequiredTrait;
16
use Yiisoft\Form\Field\Base\SizeTrait;
17
use Yiisoft\Html\Html;
18
19
use function is_string;
20
21
final class Email extends AbstractField
22
{
23
    use MinMaxLengthTrait;
24
    use MultipleTrait;
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('Email 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('email', $this->getInputName(), $value)
43 1
            ->attributes($tagAttributes)
44 1
            ->render();
45
    }
46
}
47