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

SAMLAnyURITrait::validSAMLAnyURI()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 5
nc 2
nop 2
dl 0
loc 9
rs 10
c 1
b 0
f 0
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