EmailAddressValue::validateValue()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 1
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\WSSecurity\XML\fed\Type;
6
7
use SimpleSAML\WSSecurity\Assert\Assert;
8
use SimpleSAML\XMLSchema\Type\StringValue;
9
10
use function preg_replace;
11
12
/**
13
 * @package simplesaml/ws-security
14
 */
15
class EmailAddressValue extends StringValue
16
{
17
    /**
18
     * Sanitize the content of the element.
19
     *
20
     * @param string $value  The unsanitized value
21
     * @throws \Exception on failure
22
     * @return string
23
     */
24
    protected function sanitizeValue(string $value): string
25
    {
26
        $normalizedValue = static::collapseWhitespace(static::normalizeWhitespace($value));
27
28
        // Remove prefixed schema and forward slashes
29
        return preg_replace('/^(mailto:)+/i', '', $normalizedValue);
30
    }
31
32
33
    /**
34
     * Validate the content of the element.
35
     *
36
     * @param string $value  The value to go in the XML textContent
37
     * @throws \Exception on failure
38
     * @return void
39
     */
40
    protected function validateValue(string $value): void
41
    {
42
        Assert::email($this->sanitizeValue($value));
43
    }
44
}
45