Passed
Pull Request — master (#374)
by Tim
02:30
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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A toArray() 0 3 1
A fromArray() 0 7 1
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;
0 ignored issues
show
introduced by
The trait SimpleSAML\XML\TypedTextContentTrait requires some properties which are not provided by SimpleSAML\SAML2\XML\samlp\RequesterID: $localName, $namespaceURI
Loading history...
25
26
27
    /** @var string */
28
    public const TEXTCONTENT_TYPE = EntityIDValue::class;
29
30
31
    /**
32
     * Create a class from an array
33
     *
34
     * @param array $data
35
     * @return static
36
     */
37
    public static function fromArray(array $data): static
38
    {
39
        Assert::allString($data, ArrayValidationException::class);
40
41
        $index = array_key_first($data);
42
        return new static(
43
            EntityIDValue::fromString($data[$index]),
44
        );
45
    }
46
47
48
    /**
49
     * Create an array from this class
50
     *
51
     * @return array
52
     */
53
    public function toArray(): array
54
    {
55
        return [$this->getContent()->getValue()];
56
    }
57
}
58