Completed
Push — master ( b4a32a...a386bd )
by Tim
18s queued 14s
created

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