Passed
Pull Request — master (#192)
by Alexander
04:59 queued 02:28
created

Text   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Test Coverage

Coverage 83.33%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A generateInput() 0 12 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\PlaceholderTrait;
10
use Yiisoft\Html\Html;
11
12
use function is_string;
13
14
final class Text extends AbstractField
15
{
16
    use PlaceholderTrait;
17
18 28
    protected function generateInput(): string
19
    {
20 28
        $value = $this->getAttributeValue();
21
22 28
        if (!is_string($value) && $value !== null) {
23
            throw new InvalidArgumentException('Text widget must be a string or null value.');
24
        }
25
26 28
        $tagAttributes = $this->getInputTagAttributes();
27
28
        /** @psalm-suppress MixedArgumentTypeCoercion */
29 28
        return Html::textInput($this->getInputName(), $value, $tagAttributes)->render();
30
    }
31
}
32