Passed
Branch feature/php83 (cb5cde)
by Tim
14:20
created

AuthnContextComparisonTypeValue   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 39
rs 10
wmc 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\SAML2\Type;
6
7
use SimpleSAML\Assert\Assert;
8
use SimpleSAML\SAML2\XML\samlp\AuthnContextComparisonTypeEnum;
9
use SimpleSAML\XMLSchema\Exception\SchemaViolationException;
10
use SimpleSAML\XMLSchema\Type\StringValue;
11
12
use function array_column;
13
14
/**
15
 * @package simplesamlphp/saml2
16
 */
17
class AuthnContextComparisonTypeValue extends StringValue
18
{
19
    public const string SCHEMA_TYPE = 'authnContextComparisonType';
0 ignored issues
show
Bug introduced by
A parse error occurred: Syntax error, unexpected T_STRING, expecting '=' on line 19 at column 24
Loading history...
20
21
22
    /**
23
     * Validate the value.
24
     *
25
     * @throws \Exception on failure
26
     */
27
    protected function validateValue(string $value): void
28
    {
29
        Assert::oneOf(
30
            $this->sanitizeValue($value),
31
            array_column(AuthnContextComparisonTypeEnum::cases(), 'value'),
32
            SchemaViolationException::class,
33
        );
34
    }
35
36
37
    /**
38
     * @param \SimpleSAML\SAML2\XML\samlp\AuthnContextComparisonTypeEnum $value
39
     */
40
    public static function fromEnum(AuthnContextComparisonTypeEnum $value): static
41
    {
42
        return new static($value->value);
43
    }
44
45
46
    /**
47
     * @return \SimpleSAML\SAML2\XML\samlp\AuthnContextComparisonTypeEnum $value
48
     */
49
    public function toEnum(): AuthnContextComparisonTypeEnum
50
    {
51
        return AuthnContextComparisonTypeEnum::from($this->getValue());
52
    }
53
}
54