DerivationSetValue   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 28
rs 10
c 0
b 0
f 0
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A validateValue() 0 15 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\XMLSchema\Type\Schema;
6
7
use SimpleSAML\XML\Assert\Assert;
8
use SimpleSAML\XMLSchema\Exception\SchemaViolationException;
9
use SimpleSAML\XMLSchema\XML\Enumeration\DerivationControlEnum;
10
11
use function array_column;
12
use function explode;
13
14
/**
15
 * @package simplesaml/xml-common
16
 */
17
class DerivationSetValue extends DerivationControlValue
18
{
19
    /** @var string */
20
    public const SCHEMA_TYPE = 'derivationSet';
21
22
23
    /**
24
     * Validate the value.
25
     *
26
     * @param string $value The value
27
     * @throws \SimpleSAML\XMLSchema\Exception\SchemaViolationException on failure
28
     * @return void
29
     */
30
    protected function validateValue(string $value): void
31
    {
32
        $sanitized = $this->sanitizeValue($value);
33
34
        if ($sanitized !== '#all' && $sanitized !== '') {
35
            Assert::allOneOf(
36
                explode(' ', $sanitized),
37
                array_column(
38
                    [
39
                        DerivationControlEnum::Extension,
40
                        DerivationControlEnum::Restriction,
41
                    ],
42
                    'value',
43
                ),
44
                SchemaViolationException::class,
45
            );
46
        }
47
    }
48
}
49