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

AbstractDateTimeField::generateInput()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3.0987

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 9
nc 2
nop 0
dl 0
loc 17
ccs 7
cts 9
cp 0.7778
crap 3.0987
rs 9.9666
c 1
b 0
f 0
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