Passed
Pull Request — master (#276)
by Tim
08:48 queued 06:08
created

TelephoneNumber::fromArray()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 4
nc 1
nop 1
dl 0
loc 7
rs 10
c 1
b 0
f 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\SAML2\XML\md;
6
7
use DOMElement;
8
use SimpleSAML\Assert\Assert;
9
use SimpleSAML\XML\XMLStringElementTrait;
10
11
/**
12
 * Class implementing TelephoneNumber.
13
 *
14
 * @package simplesamlphp/saml2
15
 */
16
final class TelephoneNumber extends AbstractMdElement
17
{
18
    use XMLStringElementTrait;
0 ignored issues
show
introduced by
The trait SimpleSAML\XML\XMLStringElementTrait requires some properties which are not provided by SimpleSAML\SAML2\XML\md\TelephoneNumber: $localName, $namespaceURI
Loading history...
19
20
21
    /**
22
     * @param string $content
23
     */
24
    public function __construct(string $content)
25
    {
26
        $this->setContent($content);
27
    }
28
29
30
    /**
31
     * Validate the content of the element.
32
     *
33
     * @param string $content  The value to go in the XML textContent
34
     * @throws \Exception on failure
35
     * @return void
36
     */
37
    protected function validateContent(string $content): void
38
    {
39
        Assert::notEmpty($content, 'TelephoneNumber cannot be empty');
40
    }
41
42
43
    /**
44
     * Create a class from an array
45
     *
46
     * @param array $data
47
     * @return self
48
     */
49
    public static function fromArray(array $data): object
50
    {
51
        Assert::notEmpty($data);
52
        Assert::count($data, 1);
53
54
        $index = array_key_first($data);
55
        return new self($data[$index]);
56
    }
57
58
59
    /**
60
     * Create an array from this class
61
     *
62
     * @return array
63
     */
64
    public function toArray(): array
65
    {
66
        return [$this->content];
67
    }
68
}
69