Passed
Pull Request — master (#55)
by Tim
02:07
created

UnsignedShortTrait::validUnsignedShort()   A

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
eloc 5
c 1
b 0
f 0
dl 0
loc 7
rs 10
cc 2
nc 1
nop 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\XML\Assert;
6
7
use InvalidArgumentException;
8
9
/**
10
 * @package simplesamlphp/xml-common
11
 */
12
trait UnsignedShortTrait
13
{
14
    /** @var string */
15
    private static string $unsignedShort_regex = '/^
16
        (
17
            ([+]?0*)
18
            (?:
19
                [1-9]
20
                |[1-9]\d{1,3}
21
                |[1-5]\d{4}
22
                |6[0-4]\d{3}
23
                |65[0-4]\d{2}
24
                |655[0-2]\d
25
                |6553[0-5]
26
            )
27
            |0
28
        )
29
        $/Dx';
30
31
32
    /**
33
     * @param string $value
34
     * @param string $message
35
     */
36
    protected static function validUnsignedShort(string $value, string $message = ''): void
37
    {
38
        parent::regex(
39
            $value,
40
            self::$unsignedShort_regex,
41
            $message ?: '%s is not a valid xs:unsignedShort',
42
            InvalidArgumentException::class,
43
        );
44
    }
45
}
46