Passed
Pull Request — master (#374)
by Tim
03:49 queued 01:20
created

KeyTypesValue::validateValue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
nc 1
nop 1
dl 0
loc 6
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\XML\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
     * @param string $content  The value to go in the XML textContent
22
     * @throws \Exception on failure
23
     * @return void
24
     */
25
    protected function validateValue(string $content): void
26
    {
27
        Assert::oneOf(
28
            $this->sanitizeValue($content),
29
            array_column(KeyTypesEnum::cases(), 'value'),
30
            SchemaViolationException::class,
31
        );
32
    }
33
34
35
    /**
36
     * Convert enum to value type
37
     */
38
    public static function fromEnum(KeyTypesEnum $use): static
39
    {
40
        return static::fromString($use->value);
41
    }
42
43
44
    /**
45
     * Convert this value type to enum
46
     */
47
    public function toEnum(): KeyTypesEnum
48
    {
49
        return KeyTypesEnum::from($this->getValue());
50
    }
51
}
52