Passed
Push — master ( 73feaf...96c50a )
by Petr
14:29
created

EnumOption::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 7
ccs 4
cts 4
cp 1
rs 10
cc 2
nc 2
nop 1
crap 2
1
<?php
2
3
namespace kalanis\Pohoda\Common\Attributes\Options;
4
5
use Attribute;
6
use kalanis\Pohoda\Common;
7
use kalanis\Pohoda\Common\OptionsResolver;
8
use kalanis\PohodaException;
9
10
/**
11
 * Property will be formatted as string and selected just from predefined enum
12
 */
13
#[Attribute(Attribute::TARGET_PROPERTY)]
14
final class EnumOption extends AbstractOption
15
{
16
    /**
17
     * @param class-string<object> $value
0 ignored issues
show
Documentation Bug introduced by
The doc comment class-string<object> at position 0 could not be parsed: Unknown type name 'class-string' at position 0 in class-string<object>.
Loading history...
18
     * @throws PohodaException
19
     */
20 117
    public function __construct(
21
        string $value,
22
    ) {
23 117
        if (!is_a($value, Common\Enums\EnhancedEnumInterface::class, true)) {
24 1
            throw new PohodaException('The value must be an enum instance!');
25
        }
26 116
        parent::__construct($value);
27
    }
28
29
    /**
30
     * @codeCoverageIgnore just implements interface, not need in processing
31
     * @return string
32
     */
33
    public function getNormalizer(): string
34
    {
35
        return OptionsResolver\Normalizers\Strings::class;
36
    }
37
38
    /**
39
     * {@inheritDoc}
40
     */
41 116
    public function getAction(): OptionsResolver\ActionsEnum
42
    {
43 116
        return OptionsResolver\ActionsEnum::ALLOWED_ENUMS;
44
    }
45
}
46