Passed
Push — master ( a3fda0...7c0590 )
by Tim
14:58 queued 13:28
created

EmailAddress   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 48
rs 10
c 0
b 0
f 0
wmc 3
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\EmailAddressValue;
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
use function preg_filter;
17
18
/**
19
 * Class implementing EmailAddress.
20
 *
21
 * @package simplesamlphp/saml2
22
 */
23
final class EmailAddress extends AbstractMdElement implements
24
    ArrayizableElementInterface,
25
    SchemaValidatableElementInterface
26
{
27
    use SchemaValidatableElementTrait;
28
    use TypedTextContentTrait {
29
        TypedTextContentTrait::getContent as getRawContent;
30
    }
31
32
33
    public const string TEXTCONTENT_TYPE = EmailAddressValue::class;
0 ignored issues
show
Bug introduced by
A parse error occurred: Syntax error, unexpected T_STRING, expecting '=' on line 33 at column 24
Loading history...
34
35
36
    /**
37
     * Get the content of the element.
38
     */
39
    public function getContent(): string
40
    {
41
        return preg_filter('/^/', 'mailto:', $this->getRawContent()->getValue());
42
    }
43
44
45
    /**
46
     * Create a class from an array
47
     *
48
     * @param array<string> $data
49
     */
50
    public static function fromArray(array $data): static
51
    {
52
        Assert::allString($data, ArrayValidationException::class);
53
54
        $index = array_key_first($data);
55
        return new static(
56
            EmailAddressValue::fromString($data[$index]),
57
        );
58
    }
59
60
61
    /**
62
     * Create an array from this class
63
     *
64
     * @return array<string>
65
     */
66
    public function toArray(): array
67
    {
68
        return [$this->getContent()];
69
    }
70
}
71