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

TelephoneNumber   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 37
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\md;
6
7
use SimpleSAML\SAML2\Assert\Assert;
8
use SimpleSAML\SAML2\Exception\ArrayValidationException;
9
use SimpleSAML\SAML2\Type\SAMLStringValue;
10
use SimpleSAML\XML\ArrayizableElementInterface;
11
use SimpleSAML\XML\SchemaValidatableElementInterface;
12
use SimpleSAML\XML\SchemaValidatableElementTrait;
13
use SimpleSAML\XML\TypedTextContentTrait;
14
15
use function array_key_first;
16
17
/**
18
 * Class implementing TelephoneNumber.
19
 *
20
 * @package simplesamlphp/saml2
21
 */
22
final class TelephoneNumber extends AbstractMdElement implements
23
    ArrayizableElementInterface,
24
    SchemaValidatableElementInterface
25
{
26
    use SchemaValidatableElementTrait;
27
    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...
28
29
30
    /** @var string */
31
    public const TEXTCONTENT_TYPE = SAMLStringValue::class;
32
33
34
    /**
35
     * Create a class from an array
36
     *
37
     * @param array $data
38
     * @return static
39
     */
40
    public static function fromArray(array $data): static
41
    {
42
        Assert::allString($data, ArrayValidationException::class);
43
44
        $index = array_key_first($data);
45
        return new static(
46
            SAMLStringValue::fromString($data[$index]),
47
        );
48
    }
49
50
51
    /**
52
     * Create an array from this class
53
     *
54
     * @return array
55
     */
56
    public function toArray(): array
57
    {
58
        return [$this->getContent()->getValue()];
59
    }
60
}
61