IntTrait   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 7
dl 0
loc 48
rs 10
c 0
b 0
f 0

1 Method

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