Passed
Pull Request — master (#374)
by Tim
02:43
created

GetComplete::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
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\SAMLAnyURIValue;
10
use SimpleSAML\XML\{SchemaValidatableElementInterface, SchemaValidatableElementTrait};
11
use SimpleSAML\XML\TypedTextContentTrait;
12
13
use function array_key_first;
14
use function strval;
15
16
/**
17
 * Class representing a samlp:GetComplete element.
18
 *
19
 * @package simplesaml/saml2
20
 */
21
final class GetComplete 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\GetComplete: $localName, $namespaceURI
Loading history...
25
26
    /** @var string */
27
    public const TEXTCONTENT_TYPE = SAMLAnyURIValue::class;
28
29
30
    /**
31
     * Create a class from an array
32
     *
33
     * @param array $data
34
     * @return static
35
     */
36
    public static function fromArray(array $data): static
37
    {
38
        Assert::allString($data, ArrayValidationException::class);
39
40
        $index = array_key_first($data);
41
        return new static(
42
            SAMLAnyURIValue::fromString($data[$index]),
43
        );
44
    }
45
46
47
    /**
48
     * Create an array from this class
49
     *
50
     * @return array
51
     */
52
    public function toArray(): array
53
    {
54
        return [strval($this->getContent())];
55
    }
56
}
57