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

TelephoneNumber::fromArray()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 1
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\SAML2\XML\md;
6
7
use SimpleSAML\SAML2\Assert\Assert;
8
use SimpleSAML\SAML2\Exception\ArrayValidationException;
9
use SimpleSAML\SAML2\Type\SAMLStringValue;
10
use SimpleSAML\XML\{
11
    ArrayizableElementInterface,
12
    SchemaValidatableElementInterface,
13
    SchemaValidatableElementTrait,
14
    TypedTextContentTrait,
15
};
16
17
use function array_key_first;
18
19
/**
20
 * Class implementing TelephoneNumber.
21
 *
22
 * @package simplesamlphp/saml2
23
 */
24
final class TelephoneNumber extends AbstractMdElement implements
25
    ArrayizableElementInterface,
26
    SchemaValidatableElementInterface
27
{
28
    use SchemaValidatableElementTrait;
29
    use TypedTextContentTrait;
0 ignored issues
show
introduced by
The trait SimpleSAML\XML\TypedTextContentTrait requires some properties which are not provided by SimpleSAML\SAML2\XML\md\TelephoneNumber: $localName, $namespaceURI
Loading history...
30
31
    /** @var string */
32
    public const TEXTCONTENT_TYPE = SAMLStringValue::class;
33
34
35
    /**
36
     * Create a class from an array
37
     *
38
     * @param array $data
39
     * @return static
40
     */
41
    public static function fromArray(array $data): static
42
    {
43
        Assert::allString($data, ArrayValidationException::class);
44
45
        $index = array_key_first($data);
46
        return new static(
47
            SAMLStringValue::fromString($data[$index]),
48
        );
49
    }
50
51
52
    /**
53
     * Create an array from this class
54
     *
55
     * @return array
56
     */
57
    public function toArray(): array
58
    {
59
        return [$this->getContent()->getValue()];
60
    }
61
}
62