Passed
Branch feature/php8.3 (4d3b0a)
by Tim
17:15
created

EntitiesValue   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 29
rs 10
c 0
b 0
f 0
wmc 2
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
/**
13
 * @package simplesaml/xml-common
14
 */
15
class EntitiesValue extends TokenValue implements ListTypeInterface
16
{
17
    public const string SCHEMA_TYPE = 'ENTITIES';
0 ignored issues
show
Bug introduced by
A parse error occurred: Syntax error, unexpected T_STRING, expecting '=' on line 17 at column 24
Loading history...
18
19
20
    /**
21
     * Validate the value.
22
     *
23
     * @param string $value
24
     * @throws \SimpleSAML\XMLSchema\Exception\SchemaViolationException on failure
25
     */
26
    protected function validateValue(string $value): void
27
    {
28
        // Note: value must already be sanitized before validating
29
        Assert::validEntities($this->sanitizeValue($value), SchemaViolationException::class);
30
    }
31
32
33
    /**
34
     * Convert this xs:ENTITIES to an array of xs:ENTITY items
35
     *
36
     * @return array<\SimpleSAML\XMLSchema\Type\EntityValue>
37
     */
38
    public function toArray(): array
39
    {
40
        $tokens = explode(' ', $this->getValue(), C::UNBOUNDED_LIMIT);
41
        return array_map([EntityValue::class, 'fromString'], $tokens);
42
    }
43
}
44