Passed
Pull Request — master (#192)
by Sergei
02:09
created

Text::generateInput()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 12
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3.0416

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 5
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 12
ccs 5
cts 6
cp 0.8333
crap 3.0416
rs 10
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\PlaceholderTrait;
10
11
use Yiisoft\Html\Html;
12
13
use function is_string;
14
15
final class Text extends AbstractField
16
{
17
    use PlaceholderTrait;
18
19 29
    protected function generateInput(): string
20
    {
21 29
        $value = $this->getAttributeValue();
22
23 29
        if (!is_string($value) && $value !== null) {
24
            throw new InvalidArgumentException('Text widget must be a string or null value.');
25
        }
26
27 29
        $tagAttributes = $this->getInputTagAttributes();
28
29
        /** @psalm-suppress MixedArgumentTypeCoercion */
30 29
        return Html::textInput($this->getInputName(), $value, $tagAttributes)->render();
31
    }
32
}
33