UnsignedLongTrait::validUnsignedLong()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 1
nop 2
dl 0
loc 7
rs 10
c 0
b 0
f 0
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 UnsignedLongTrait
13
{
14
    private static string $unsignedLong_regex = '/^
15
        (?:
16
            ([+]?[0]*)
17
            (
18
                ([1-9])
19
                |([1-9]\d{1,18})
20
                |([1]\d{18})
21
                |(1[0-7]\d{18})
22
                |(18[0-3]\d{17})
23
                |(184[0-3]\d{16})
24
                |(1844[0-5]\d{15})
25
                |(18446[0-6]\d{14})
26
                |(184467[0-3]\d{13})
27
                |(1844674[0-3]\d{12})
28
                |(18446744[0]\d{3}[0]\d{10})
29
                |(184467440[0-6]\d{10})
30
                |(1844674407[0-2]\d{9})
31
                |(18446744073[0-6]\d{8})
32
                |(1844674407370[0-8]\d{6})
33
                |(18446744073709[0-4]\d{5})
34
                |(184467440737095[0-4]\d{4})
35
                |(1844674407370955[0]\d{3})
36
                |(18446744073709551[0-5]\d{2})
37
                |(184467440737095516[0]\d)
38
                |(1844674407370955161[0-5])
39
            )
40
            |0
41
        )
42
        $/Dx';
43
44
45
    /**
46
     * @param string $value
47
     * @param string $message
48
     */
49
    protected static function validUnsignedLong(string $value, string $message = ''): void
50
    {
51
        parent::regex(
52
            $value,
53
            self::$unsignedLong_regex,
54
            $message ?: '%s is not a valid xs:unsignedLong',
55
            InvalidArgumentException::class,
56
        );
57
    }
58
}
59