EmailAddressValue   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A validateValue() 0 3 1
A sanitizeValue() 0 6 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