IntTrait::validInt()   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 IntTrait
13
{
14
    private static string $int_regex = '/^
15
        (
16
            (
17
                ([-+]?[0]*)
18
                (?:
19
                    [1-9]
20
                    |214748364[0-7]
21
                    |[1-9][0-9]
22
                    |[1-9][0-9][0-9]
23
                    |[1-9][0-9][0-9][0-9]
24
                    |[1-9][0-9][0-9][0-9][0-9]
25
                    |[1-9][0-9][0-9][0-9][0-9][0-9]
26
                    |[1-9][0-9][0-9][0-9][0-9][0-9][0-9]
27
                    |[1-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]
28
                    |[1-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]
29
                    |1[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]
30
                    |20[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]
31
                    |21[0-3][0-9][0-9][0-9][0-9][0-9][0-9][0-9]
32
                    |214[0-6][0-9][0-9][0-9][0-9][0-9][0-9]
33
                    |2147[0-3][0-9][0-9][0-9][0-9][0-9]
34
                    |21474[0-7][0-9][0-9][0-9][0-9]
35
                    |214748[0-2][0-9][0-9][0-9]
36
                    |2147483[0-5][0-9][0-9]
37
                    |21474836[0-3][0-9]
38
                    |[0-9]
39
                    |214748364[0-7]
40
                )
41
            )|
42
            0|
43
            ((-([0]*)?)2147483648)
44
        )
45
        $/Dx';
46
47
48
    /**
49
     * @param string $value
50
     * @param string $message
51
     */
52
    protected static function validInt(string $value, string $message = ''): void
53
    {
54
        parent::regex(
55
            $value,
56
            self::$int_regex,
57
            $message ?: '%s is not a valid xs:int',
58
            InvalidArgumentException::class,
59
        );
60
    }
61
}
62