Passed
Pull Request — master (#55)
by Tim
01:56
created

LongTrait   A

Complexity

Total Complexity 2

Size/Duplication

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

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
    /** @var string */
15
    private static string $long_regex = '/^
16
        (
17
            ([-+]?[0]*)?
18
            (?:
19
                [1-9]
20
                |[1-9]\d{1,14}
21
                |1000000000000000
22
                |1000000000000000[1-9]
23
                |10000000000000000[1-9]
24
                |[1-8][1-9]\d{17}
25
                |9[01]\d{17}
26
                |92[01]\d{16}
27
                |922[0-2]\d{15}
28
                |9223[0-2]\d{14}
29
                |92233[0-6]\d{13}
30
                |922337[01]\d{12}
31
                |92233720[0-2]\d{10}
32
                |922337203[0-5]\d{9}
33
                |9223372036[0-7]\d{8}
34
                |92233720368[0-4]\d{7}
35
                |922337203685[0-3]\d{6}
36
                |9223372036854[0-6]\d{5}
37
                |92233720368547[0-6]\d{4}
38
                |922337203685477[0-4]\d{3}
39
                |9223372036854775[0-7]\d{2}
40
                |922337203685477580[0-7]
41
            )
42
            |0
43
            |(-([0]*)?)9223372036854775808
44
        )
45
        $/Dx';
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