UnsignedIntTrait   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 7
c 1
b 0
f 0
dl 0
loc 36
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A validUnsignedInt() 0 7 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 UnsignedIntTrait
13
{
14
    /** @var string */
15
    private static string $unsignedInt_regex = '/^
16
        (
17
            ([+]?0*)
18
            (?:
19
                [1-9]
20
                |[1-9]\d{1,8}
21
                |[1-3]\d{9}
22
                |4[01]\d{8}
23
                |42[0-8]\d{7}
24
                |429[0-3]\d{6}
25
                |4294[0-8]\d{5}
26
                |42949[0-5]\d{4}
27
                |429496[0-6]\d{3}
28
                |4294967[01]\d{2}
29
                |42949672[0-8]\d
30
                |429496729[0-5]
31
            )
32
            |0
33
        )
34
        $/Dx';
35
36
37
    /**
38
     * @param string $value
39
     * @param string $message
40
     */
41
    protected static function validUnsignedInt(string $value, string $message = ''): void
42
    {
43
        parent::regex(
44
            $value,
45
            self::$unsignedInt_regex,
46
            $message ?: '%s is not a valid xs:unsignedInt',
47
            InvalidArgumentException::class,
48
        );
49
    }
50
}
51