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

EnumOption   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 7
c 1
b 0
f 0
dl 0
loc 31
ccs 6
cts 6
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 2
A getNormalizer() 0 3 1
A getAction() 0 3 1
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