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

SAMLAnyURITrait   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
dl 0
loc 17
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
     * @param string $value
19
     * @param string $message
20
     */
21
    protected static function validSAMLAnyURI(string $value, string $message = ''): void
22
    {
23
        parent::validAnyURI($value);
24
25
        try {
26
            // If it doesn't have a scheme, it's not an absolute URI
27
            parent::regex($value, self::$scheme_regex, $message ?: '%s is not a SAML2-compliant URI');
28
        } catch (AssertionFailedException $e) {
29
            throw new ProtocolViolationException($e->getMessage());
30
        }
31
    }
32
}
33