Passed
Push — master ( 765b41...e6bf79 )
by Tim
03:49 queued 01:38
created

DecisionTypeValue::toEnum()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\SAML11\Type;
6
7
use SimpleSAML\Assert\Assert;
8
use SimpleSAML\SAML11\XML\Enumeration\DecisionTypeEnum;
9
use SimpleSAML\XMLSchema\Exception\SchemaViolationException;
10
use SimpleSAML\XMLSchema\Type\StringValue;
11
12
use function array_column;
13
14
/**
15
 * @package simplesamlphp/saml11
16
 */
17
class DecisionTypeValue extends StringValue
18
{
19
    /** @var string */
20
    public const SCHEMA_TYPE = 'decisionType';
21
22
23
    /**
24
     * Validate the value.
25
     *
26
     * @param string $value The value
27
     * @throws \Exception on failure
28
     * @return void
29
     */
30
    protected function validateValue(string $value): void
31
    {
32
        Assert::oneOf(
33
            $this->sanitizeValue($value),
34
            array_column(DecisionTypeEnum::cases(), 'value'),
35
            SchemaViolationException::class,
36
        );
37
    }
38
39
40
    /**
41
     * @param \SimpleSAML\SAML11\XML\Enumeration\DecisionTypeEnum $value
42
     * @return static
43
     */
44
    public static function fromEnum(DecisionTypeEnum $value): static
45
    {
46
        return new static($value->value);
47
    }
48
49
50
    /**
51
     * @return \SimpleSAML\SAML11\XML\Enumeration\DecisionTypeEnum $value
52
     */
53
    public function toEnum(): DecisionTypeEnum
54
    {
55
        return DecisionTypeEnum::from($this->getValue());
56
    }
57
}
58