Completed
Push — master ( b4a32a...a386bd )
by Tim
18s queued 14s
created

EntitiesValue::validateValue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
dl 0
loc 4
rs 10
c 1
b 0
f 0
cc 1
nc 1
nop 1
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
/**
12
 * @package simplesaml/xml-common
13
 */
14
class EntitiesValue extends TokenValue implements ListTypeInterface
15
{
16
    /** @var string */
17
    public const SCHEMA_TYPE = 'ENTITIES';
18
19
20
    /**
21
     * Validate the value.
22
     *
23
     * @param string $value
24
     * @throws \SimpleSAML\XML\Exception\SchemaViolationException on failure
25
     * @return void
26
     */
27
    protected function validateValue(string $value): void
28
    {
29
        // Note: value must already be sanitized before validating
30
        Assert::validEntities($this->sanitizeValue($value), SchemaViolationException::class);
31
    }
32
33
34
    /**
35
     * Convert this xs:ENTITIES to an array of xs:ENTITY items
36
     *
37
     * @return array<\SimpleSAML\XML\Type\EntityValue>
38
     */
39
    public function toArray(): array
40
    {
41
        $tokens = explode(' ', $this->getValue(), C::UNBOUNDED_LIMIT);
42
        return array_map([EntityValue::class, 'fromString'], $tokens);
43
    }
44
}
45