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

SAMLAnyURITrait   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A validSAMLAnyURI() 0 9 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\SAML2\Assert;
6
7
use SimpleSAML\Assert\AssertionFailedException;
8
use SimpleSAML\SAML2\Exception\ProtocolViolationException;
9
10
/**
11
 * @package simplesamlphp/saml2
12
 */
13
trait SAMLAnyURITrait
14
{
15
    private static string $scheme_regex = '/^([a-z][a-z0-9\+\-\.]+[:])/i';
16
17
18
    /**
19
     * @param string $value
20
     * @param string $message
21
     */
22
    protected static function validSAMLAnyURI(string $value, string $message = ''): void
23
    {
24
        parent::validAnyURI($value);
25
26
        try {
27
            // If it doesn't have a scheme, it's not an absolute URI
28
            parent::regex($value, self::$scheme_regex, $message ?: '%s is not a SAML2-compliant URI');
29
        } catch (AssertionFailedException $e) {
30
            throw new ProtocolViolationException($e->getMessage());
31
        }
32
    }
33
}
34