Passed
Pull Request — master (#55)
by Tim
02:14
created

NMTokensValue::toArray()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\XML\Type;
6
7
use SimpleSAML\XML\Assert\Assert;
8
use SimpleSAML\XML\Constants as C;
9
use SimpleSAML\XML\Exception\SchemaViolationException;
10
11
use function array_map;
12
use function explode;
13
14
/**
15
 * @package simplesaml/xml-common
16
 */
17
class NMTokensValue extends TokenValue implements ListTypeInterface
18
{
19
    /** @var string */
20
    public const SCHEMA_TYPE = 'xs:NMTOKENS';
21
22
23
    /**
24
     * Validate the value.
25
     *
26
     * @param string $value
27
     * @throws \SimpleSAML\XML\Exception\SchemaViolationException on failure
28
     * @return void
29
     */
30
    protected function validateValue(string $value): void
31
    {
32
        // Note: value must already be sanitized before validating
33
        Assert::validNMTokens($this->sanitizeValue($value), SchemaViolationException::class);
34
    }
35
36
37
    /**
38
     * Convert this xs:NMTokens to an array of xs:NMToken items
39
     *
40
     * @return array<\SimpleSAML\XML\Type\NMTokenValue>
41
     */
42
    public function toArray(): array
43
    {
44
        $tokens = explode(' ', $this->getValue(), C::UNBOUNDED_LIMIT);
45
        return array_map([NMTokenValue::class, 'fromString'], $tokens);
46
    }
47
}
48