Passed
Push — master ( 8413b2...00f101 )
by Tim
02:19
created

BlockSetValue::validateValue()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 9
nc 2
nop 1
dl 0
loc 17
rs 9.9666
c 0
b 0
f 0
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\XML\Constants as C;
9
use SimpleSAML\XMLSchema\Exception\SchemaViolationException;
10
use SimpleSAML\XMLSchema\Type\NMTokenValue;
11
use SimpleSAML\XMLSchema\XML\Enumeration\DerivationControlEnum;
12
13
use function explode;
14
15
/**
16
 * @package simplesaml/xml-common
17
 */
18
class BlockSetValue extends NMTokenValue
19
{
20
    /** @var string */
21
    public const SCHEMA_TYPE = 'blockSet';
22
23
24
    /**
25
     * Validate the value.
26
     *
27
     * @param string $value The value
28
     * @throws \Exception on failure
29
     * @return void
30
     */
31
    protected function validateValue(string $value): void
32
    {
33
        $sanitized = $this->sanitizeValue($value);
34
35
        if ($sanitized !== '#all' && $sanitized !== '') {
36
            $list = explode(' ', $sanitized, C::UNBOUNDED_LIMIT);
37
38
            // After filtering the allowed values, there should be nothing left
39
            $filtered = array_diff(
40
                $list,
41
                [
42
                    DerivationControlEnum::Extension->value,
43
                    DerivationControlEnum::Restriction->value,
44
                    DerivationControlEnum::Substitution->value,
45
                ],
46
            );
47
            Assert::isEmpty($filtered, SchemaViolationException::class);
48
        }
49
    }
50
}
51