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

AbstractDateTimeField   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Test Coverage

Coverage 77.78%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
dl 0
loc 26
ccs 7
cts 9
cp 0.7778
rs 10
c 1
b 0
f 0
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A generateInput() 0 17 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Form\Field\Base;
6
7
use InvalidArgumentException;
8
use ReflectionClass;
9
use Yiisoft\Html\Html;
10
11
use function is_string;
12
13
abstract class AbstractDateTimeField extends AbstractField
14
{
15
    use MinMaxTrait;
16
    use ReadonlyTrait;
17
    use RequiredTrait;
18
19 4
    final protected function generateInput(): string
20
    {
21 4
        $value = $this->getAttributeValue();
22
23 4
        if (!is_string($value) && $value !== null) {
24
            throw new InvalidArgumentException(
25
                (new ReflectionClass($this))->getShortName() .
26
                ' widget must be a string or null value.'
27
            );
28
        }
29
30 4
        $tagAttributes = $this->getInputTagAttributes();
31
32
        /** @psalm-suppress MixedArgumentTypeCoercion */
33 4
        return Html::input($this->getInputType(), $this->getInputName(), $value)
34 4
            ->attributes($tagAttributes)
35 4
            ->render();
36
    }
37
38
    abstract protected function getInputType(): string;
39
}
40