Passed
Pull Request — master (#159)
by Sergei
02:17
created

InputText::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
use Yiisoft\Form\Field\Base\PlaceholderTrait;
10
use Yiisoft\Html\Html;
11
12
use function is_string;
13
14
final class InputText extends AbstractField
15
{
16
    use PlaceholderTrait;
17
18 29
    protected function generateInput(): string
19
    {
20 29
        $value = $this->getAttributeValue();
21
22 29
        if (!is_string($value) && $value !== null) {
23
            throw new InvalidArgumentException('Text widget must be a string or null value.');
24
        }
25
26 29
        $tagAttributes = $this->getFormElementTagAttributes();
27
28 29
        $this->prepareIdInFormElementTagAttributes($tagAttributes);
29 29
        $this->preparePlaceholderInFormElementTagAttributes($tagAttributes);
30
31 29
        return Html::textInput($this->getInputName(), $value, $tagAttributes)->render();
32
    }
33
}
34