KeyTypesValue::toEnum()   A
last analyzed

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
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\SAML2\Type;
6
7
use SimpleSAML\SAML2\Assert\Assert;
8
use SimpleSAML\SAML2\XML\md\KeyTypesEnum;
9
use SimpleSAML\XMLSchema\Exception\SchemaViolationException;
10
11
use function array_column;
12
13
/**
14
 * @package simplesaml/saml2
15
 */
16
class KeyTypesValue extends SAMLStringValue
17
{
18
    /**
19
     * Validate the content of the element.
20
     *
21
     * @throws \Exception on failure
22
     */
23
    protected function validateValue(string $content): void
24
    {
25
        Assert::oneOf(
26
            $this->sanitizeValue($content),
27
            array_column(KeyTypesEnum::cases(), 'value'),
28
            SchemaViolationException::class,
29
        );
30
    }
31
32
33
    /**
34
     * Convert enum to value type
35
     */
36
    public static function fromEnum(KeyTypesEnum $use): static
37
    {
38
        return static::fromString($use->value);
39
    }
40
41
42
    /**
43
     * Convert this value type to enum
44
     */
45
    public function toEnum(): KeyTypesEnum
46
    {
47
        return KeyTypesEnum::from($this->getValue());
48
    }
49
}
50