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

NMTokensValue   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 29
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A toArray() 0 4 1
A validateValue() 0 4 1
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\Interface\ListTypeInterface;
11
12
use function array_map;
13
use function explode;
14
15
/**
16
 * @package simplesaml/xml-common
17
 */
18
class NMTokensValue extends TokenValue implements ListTypeInterface
19
{
20
    /** @var string */
21
    public const SCHEMA_TYPE = 'NMTOKENS';
22
23
24
    /**
25
     * Validate the value.
26
     *
27
     * @param string $value
28
     * @throws \SimpleSAML\XMLSchema\Exception\SchemaViolationException on failure
29
     * @return void
30
     */
31
    protected function validateValue(string $value): void
32
    {
33
        // Note: value must already be sanitized before validating
34
        Assert::validNMTokens($this->sanitizeValue($value), SchemaViolationException::class);
35
    }
36
37
38
    /**
39
     * Convert this xs:NMTokens to an array of xs:NMToken items
40
     *
41
     * @return array<\SimpleSAML\XMLSchema\Type\NMTokenValue>
42
     */
43
    public function toArray(): array
44
    {
45
        $tokens = explode(' ', $this->getValue(), C::UNBOUNDED_LIMIT);
46
        return array_map([NMTokenValue::class, 'fromString'], $tokens);
47
    }
48
}
49