Passed
Pull Request — master (#159)
by Alexander
04:51 queued 02:29
created

InputText   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 15
Duplicated Lines 0 %

Test Coverage

Coverage 83.33%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 6
dl 0
loc 15
ccs 5
cts 6
cp 0.8333
rs 10
c 3
b 0
f 0
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A generateInput() 0 11 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\PlaceholderInterface;
10
use Yiisoft\Form\Field\Base\PlaceholderTrait;
11
use Yiisoft\Html\Html;
12
13
use function is_string;
14
15
final class InputText extends AbstractField implements PlaceholderInterface
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->getFormElementTagAttributes();
28
29 29
        return Html::textInput($this->getInputName(), $value, $tagAttributes)->render();
30
    }
31
}
32