Passed
Pull Request — master (#61)
by Tim
02:17
created

BlockSetValue::validateValue()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

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