LongTrait   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A validLong() 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 LongTrait
13
{
14
    private static string $long_regex = '/^
15
        (
16
            ([-+]?[0]*)?
17
            (?:
18
                [1-9]
19
                |[1-9]\d{1,14}
20
                |1000000000000000
21
                |1000000000000000[1-9]
22
                |10000000000000000[1-9]
23
                |[1-8][1-9]\d{17}
24
                |9[01]\d{17}
25
                |92[01]\d{16}
26
                |922[0-2]\d{15}
27
                |9223[0-2]\d{14}
28
                |92233[0-6]\d{13}
29
                |922337[01]\d{12}
30
                |92233720[0-2]\d{10}
31
                |922337203[0-5]\d{9}
32
                |9223372036[0-7]\d{8}
33
                |92233720368[0-4]\d{7}
34
                |922337203685[0-3]\d{6}
35
                |9223372036854[0-6]\d{5}
36
                |92233720368547[0-6]\d{4}
37
                |922337203685477[0-4]\d{3}
38
                |9223372036854775[0-7]\d{2}
39
                |922337203685477580[0-7]
40
            )
41
            |0
42
            |(-([0]*)?)9223372036854775808
43
        )
44
        $/Dx';
45
46
47
    /**
48
     * @param string $value
49
     * @param string $message
50
     */
51
    protected static function validLong(string $value, string $message = ''): void
52
    {
53
        parent::regex(
54
            $value,
55
            self::$long_regex,
56
            $message ?: '%s is not a valid xs:long',
57
            InvalidArgumentException::class,
58
        );
59
    }
60
}
61