Passed
Pull Request — master (#374)
by Tim
11:54 queued 09:21
created

GeolocationValue   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A validateValue() 0 4 1
A sanitizeValue() 0 6 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\SAML2\Type;
6
7
use SimpleSAML\SAML2\Assert\Assert;
8
9
/**
10
 * @package simplesaml/saml2
11
 */
12
class GeolocationValue extends SAMLAnyURIValue
13
{
14
    /**
15
     * Sanitize the content of the element.
16
     *
17
     * @param string $value  The unsanitized value
18
     * @throws \Exception on failure
19
     * @return string
20
     */
21
    protected function sanitizeValue(string $value): string
22
    {
23
        $normalizedValue = static::collapseWhitespace(static::normalizeWhitespace($value));
24
25
        // Remove duplicate scheme
26
        return preg_replace('/^(geo:)+/i', 'geo:', $normalizedValue);
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
     * @return void
35
     */
36
    protected function validateValue(string $value): void
37
    {
38
        // Note: value must already be sanitized before validating
39
        Assert::validGeolocation($this->sanitizeValue($value));
40
    }
41
}
42