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

EmailAddressValue   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
dl 0
loc 28
rs 10
c 1
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A sanitizeValue() 0 6 1
A validateValue() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\SAML2\Type;
6
7
use SimpleSAML\SAML2\Assert\Assert;
8
9
use function preg_replace;
10
11
/**
12
 * @package simplesaml/saml2
13
 */
14
class EmailAddressValue extends SAMLStringValue
15
{
16
    /**
17
     * Sanitize the content of the element.
18
     *
19
     * @param string $value  The unsanitized value
20
     * @throws \Exception on failure
21
     * @return string
22
     */
23
    protected function sanitizeValue(string $value): string
24
    {
25
        $normalizedValue = static::collapseWhitespace(static::normalizeWhitespace($value));
26
27
        // Remove prefixed schema and forward slashes
28
        return preg_replace('/^(mailto:)+/i', '', $normalizedValue);
29
    }
30
31
32
    /**
33
     * Validate the content of the element.
34
     *
35
     * @param string $value  The value to go in the XML textContent
36
     * @throws \Exception on failure
37
     * @return void
38
     */
39
    protected function validateValue(string $value): void
40
    {
41
        Assert::email($this->sanitizeValue($value));
42
    }
43
}
44