Passed
Branch feature/php83 (cb5cde)
by Tim
14:20
created

RequesterID   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 35
rs 10
c 0
b 0
f 0
wmc 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\SAML2\XML\samlp;
6
7
use SimpleSAML\SAML2\Assert\Assert;
8
use SimpleSAML\SAML2\Exception\ArrayValidationException;
9
use SimpleSAML\SAML2\Type\EntityIDValue;
10
use SimpleSAML\XML\SchemaValidatableElementInterface;
11
use SimpleSAML\XML\SchemaValidatableElementTrait;
12
use SimpleSAML\XML\TypedTextContentTrait;
13
14
use function array_key_first;
15
16
/**
17
 * Class representing a samlp:RequesterID element.
18
 *
19
 * @package simplesaml/saml2
20
 */
21
final class RequesterID extends AbstractSamlpElement implements SchemaValidatableElementInterface
22
{
23
    use SchemaValidatableElementTrait;
24
    use TypedTextContentTrait;
25
26
27
    public const string TEXTCONTENT_TYPE = EntityIDValue::class;
0 ignored issues
show
Bug introduced by
A parse error occurred: Syntax error, unexpected T_STRING, expecting '=' on line 27 at column 24
Loading history...
28
29
30
    /**
31
     * Create a class from an array
32
     *
33
     * @param array<string> $data
34
     */
35
    public static function fromArray(array $data): static
36
    {
37
        Assert::allString($data, ArrayValidationException::class);
38
39
        $index = array_key_first($data);
40
        return new static(
41
            EntityIDValue::fromString($data[$index]),
42
        );
43
    }
44
45
46
    /**
47
     * Create an array from this class
48
     *
49
     * @return array<string>
50
     */
51
    public function toArray(): array
52
    {
53
        return [$this->getContent()->getValue()];
54
    }
55
}
56