Passed
Pull Request — master (#55)
by Tim
02:00
created

IntTrait   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 47
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 47
rs 10

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
     * @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