DomainTrait::validDomain()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 5
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 7
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\SAML2\Assert;
6
7
use SimpleSAML\SAML2\Exception\ProtocolViolationException;
8
9
/**
10
 * @package simplesamlphp/saml2
11
 */
12
trait DomainTrait
13
{
14
    private static string $domain_regex = '/^
15
      (?!\-)
16
      (?:(?:[a-zA-Z\d][a-zA-Z\d\-]{0,61})?[a-zA-Z\d]\.){0,126}
17
      (?!\d+)[a-zA-Z\d]{1,63}
18
      $/Dxi';
19
20
21
    /**
22
     */
23
    protected static function validDomain(string $value, string $message = ''): void
24
    {
25
        parent::regex(
26
            $value,
27
            self::$domain_regex,
28
            $message ?: '%s is not a valid domain name',
29
            ProtocolViolationException::class,
30
        );
31
    }
32
}
33