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

Password   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Test Coverage

Coverage 83.33%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
dl 0
loc 21
ccs 5
cts 6
cp 0.8333
rs 10
c 1
b 0
f 0
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\MinMaxLengthTrait;
10
use Yiisoft\Form\Field\Base\PatternTrait;
11
use Yiisoft\Form\Field\Base\PlaceholderTrait;
12
use Yiisoft\Form\Field\Base\ReadonlyTrait;
13
use Yiisoft\Form\Field\Base\RequiredTrait;
14
use Yiisoft\Form\Field\Base\SizeTrait;
15
use Yiisoft\Html\Html;
16
17
use function is_string;
18
19
/**
20
 * A one-line plain-text edit control for entering a password.
21
 *
22
 * @link https://html.spec.whatwg.org/multipage/input.html#password-state-(type=password)
23
 */
24
final class Password extends AbstractField
25
{
26
    use MinMaxLengthTrait;
27
    use PatternTrait;
28
    use PlaceholderTrait;
29
    use ReadonlyTrait;
30
    use RequiredTrait;
31
    use SizeTrait;
32
33 2
    protected function generateInput(): string
34
    {
35 2
        $value = $this->getAttributeValue();
36
37 2
        if (!is_string($value) && $value !== null) {
38
            throw new InvalidArgumentException('Password widget must be a string or null value.');
39
        }
40
41 2
        $tagAttributes = $this->getInputTagAttributes();
42
43
        /** @psalm-suppress MixedArgumentTypeCoercion */
44 2
        return Html::passwordInput($this->getInputName(), $value, $tagAttributes)->render();
45
    }
46
}
47