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

LongTrait::validLong()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
c 1
b 0
f 0
dl 0
loc 7
rs 10
cc 2
nc 1
nop 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 = '/^(((-[0]*([1-9]|[1-8][0-9]|9[0-9]|[1-8][0-9]{2}|9[0-8][0-9]|99[0-9]|[1-8][0-9]{3}|9[0-8][0-9]{2}|99[0-8][0-9]|999[0-9]|[1-8][0-9]{4}|9[0-8][0-9]{3}|99[0-8][0-9]{2}|999[0-8][0-9]|9999[0-9]|[1-8][0-9]{5}|9[0-8][0-9]{4}|99[0-8][0-9]{3}|999[0-8][0-9]{2}|9999[0-8][0-9]|99999[0-9]|[1-8][0-9]{6}|9[0-8][0-9]{5}|99[0-8][0-9]{4}|999[0-8][0-9]{3}|9999[0-8][0-9]{2}|99999[0-8][0-9]|999999[0-9]|[1-8][0-9]{7}|9[0-8][0-9]{6}|99[0-8][0-9]{5}|999[0-8][0-9]{4}|9999[0-8][0-9]{3}|99999[0-8][0-9]{2}|999999[0-8][0-9]|9999999[0-9]|[1-8][0-9]{8}|9[0-8][0-9]{7}|99[0-8][0-9]{6}|999[0-8][0-9]{5}|9999[0-8][0-9]{4}|99999[0-8][0-9]{3}|999999[0-8][0-9]{2}|9999999[0-8][0-9]|99999999[0-9]|[1-8][0-9]{9}|9[0-8][0-9]{8}|99[0-8][0-9]{7}|999[0-8][0-9]{6}|9999[0-8][0-9]{5}|99999[0-8][0-9]{4}|999999[0-8][0-9]{3}|9999999[0-8][0-9]{2}|99999999[0-8][0-9]|999999999[0-9]|[1-8][0-9]{10}|9[0-8][0-9]{9}|99[0-8][0-9]{8}|999[0-8][0-9]{7}|9999[0-8][0-9]{6}|99999[0-8][0-9]{5}|999999[0-8][0-9]{4}|9999999[0-8][0-9]{3}|99999999[0-8][0-9]{2}|999999999[0-8][0-9]|9999999999[0-9]|[1-8][0-9]{11}|9[0-8][0-9]{10}|99[0-8][0-9]{9}|999[0-8][0-9]{8}|9999[0-8][0-9]{7}|99999[0-8][0-9]{6}|999999[0-8][0-9]{5}|9999999[0-8][0-9]{4}|99999999[0-8][0-9]{3}|999999999[0-8][0-9]{2}|9999999999[0-8][0-9]|99999999999[0-9]|[1-8][0-9]{12}|9[0-8][0-9]{11}|99[0-8][0-9]{10}|999[0-8][0-9]{9}|9999[0-8][0-9]{8}|99999[0-8][0-9]{7}|999999[0-8][0-9]{6}|9999999[0-8][0-9]{5}|99999999[0-8][0-9]{4}|999999999[0-8][0-9]{3}|9999999999[0-8][0-9]{2}|99999999999[0-8][0-9]|999999999999[0-9]|[1-8][0-9]{13}|9[0-8][0-9]{12}|99[0-8][0-9]{11}|999[0-8][0-9]{10}|9999[0-8][0-9]{9}|99999[0-8][0-9]{8}|999999[0-8][0-9]{7}|9999999[0-8][0-9]{6}|99999999[0-8][0-9]{5}|999999999[0-8][0-9]{4}|9999999999[0-8][0-9]{3}|99999999999[0-8][0-9]{2}|999999999999[0-8][0-9]|9999999999999[0-9]|[1-8][0-9]{14}|9[0-8][0-9]{13}|99[0-8][0-9]{12}|999[0-8][0-9]{11}|9999[0-8][0-9]{10}|99999[0-8][0-9]{9}|999999[0-8][0-9]{8}|9999999[0-8][0-9]{7}|99999999[0-8][0-9]{6}|999999999[0-8][0-9]{5}|9999999999[0-8][0-9]{4}|99999999999[0-8][0-9]{3}|999999999999[0-8][0-9]{2}|9999999999999[0-8][0-9]|99999999999999[0-9]|[1-8][0-9]{15}|9[0-8][0-9]{14}|99[0-8][0-9]{13}|999[0-8][0-9]{12}|9999[0-8][0-9]{11}|99999[0-8][0-9]{10}|999999[0-8][0-9]{9}|9999999[0-8][0-9]{8}|99999999[0-8][0-9]{7}|999999999[0-8][0-9]{6}|9999999999[0-8][0-9]{5}|99999999999[0-8][0-9]{4}|999999999999[0-8][0-9]{3}|9999999999999[0-8][0-9]{2}|99999999999999[0-8][0-9]|999999999999999[0-9]|[1-8][0-9]{16}|9[0-8][0-9]{15}|99[0-8][0-9]{14}|999[0-8][0-9]{13}|9999[0-8][0-9]{12}|99999[0-8][0-9]{11}|999999[0-8][0-9]{10}|9999999[0-8][0-9]{9}|99999999[0-8][0-9]{8}|999999999[0-8][0-9]{7}|9999999999[0-8][0-9]{6}|99999999999[0-8][0-9]{5}|999999999999[0-8][0-9]{4}|9999999999999[0-8][0-9]{3}|99999999999999[0-8][0-9]{2}|999999999999999[0-8][0-9]|9999999999999999[0-9]|[1-8][0-9]{17}|9[0-8][0-9]{16}|99[0-8][0-9]{15}|999[0-8][0-9]{14}|9999[0-8][0-9]{13}|99999[0-8][0-9]{12}|999999[0-8][0-9]{11}|9999999[0-8][0-9]{10}|99999999[0-8][0-9]{9}|999999999[0-8][0-9]{8}|9999999999[0-8][0-9]{7}|99999999999[0-8][0-9]{6}|999999999999[0-8][0-9]{5}|9999999999999[0-8][0-9]{4}|99999999999999[0-8][0-9]{3}|999999999999999[0-8][0-9]{2}|9999999999999999[0-8][0-9]|99999999999999999[0-9]|[1-8][0-9]{18}|9[01][0-9]{17}|92[01][0-9]{16}|922[0-2][0-9]{15}|9223[0-2][0-9]{14}|92233[0-6][0-9]{13}|922337[01][0-9]{12}|92233720[0-2][0-9]{10}|922337203[0-5][0-9]{9}|9223372036[0-7][0-9]{8}|92233720368[0-4][0-9]{7}|922337203685[0-3][0-9]{6}|9223372036854[0-6][0-9]{5}|92233720368547[0-6][0-9]{4}|922337203685477[0-4][0-9]{3}|9223372036854775[0-7][0-9]{2}|922337203685477580[0-8]))|([+]?[0]*([1-9]|[1-8][0-9]|9[0-9]|[1-8][0-9]{2}|9[0-8][0-9]|99[0-9]|[1-8][0-9]{3}|9[0-8][0-9]{2}|99[0-8][0-9]|999[0-9]|[1-8][0-9]{4}|9[0-8][0-9]{3}|99[0-8][0-9]{2}|999[0-8][0-9]|9999[0-9]|[1-8][0-9]{5}|9[0-8][0-9]{4}|99[0-8][0-9]{3}|999[0-8][0-9]{2}|9999[0-8][0-9]|99999[0-9]|[1-8][0-9]{6}|9[0-8][0-9]{5}|99[0-8][0-9]{4}|999[0-8][0-9]{3}|9999[0-8][0-9]{2}|99999[0-8][0-9]|999999[0-9]|[1-8][0-9]{7}|9[0-8][0-9]{6}|99[0-8][0-9]{5}|999[0-8][0-9]{4}|9999[0-8][0-9]{3}|99999[0-8][0-9]{2}|999999[0-8][0-9]|9999999[0-9]|[1-8][0-9]{8}|9[0-8][0-9]{7}|99[0-8][0-9]{6}|999[0-8][0-9]{5}|9999[0-8][0-9]{4}|99999[0-8][0-9]{3}|999999[0-8][0-9]{2}|9999999[0-8][0-9]|99999999[0-9]|[1-8][0-9]{9}|9[0-8][0-9]{8}|99[0-8][0-9]{7}|999[0-8][0-9]{6}|9999[0-8][0-9]{5}|99999[0-8][0-9]{4}|999999[0-8][0-9]{3}|9999999[0-8][0-9]{2}|99999999[0-8][0-9]|999999999[0-9]|[1-8][0-9]{10}|9[0-8][0-9]{9}|99[0-8][0-9]{8}|999[0-8][0-9]{7}|9999[0-8][0-9]{6}|99999[0-8][0-9]{5}|999999[0-8][0-9]{4}|9999999[0-8][0-9]{3}|99999999[0-8][0-9]{2}|999999999[0-8][0-9]|9999999999[0-9]|[1-8][0-9]{11}|9[0-8][0-9]{10}|99[0-8][0-9]{9}|999[0-8][0-9]{8}|9999[0-8][0-9]{7}|99999[0-8][0-9]{6}|999999[0-8][0-9]{5}|9999999[0-8][0-9]{4}|99999999[0-8][0-9]{3}|999999999[0-8][0-9]{2}|9999999999[0-8][0-9]|99999999999[0-9]|[1-8][0-9]{12}|9[0-8][0-9]{11}|99[0-8][0-9]{10}|999[0-8][0-9]{9}|9999[0-8][0-9]{8}|99999[0-8][0-9]{7}|999999[0-8][0-9]{6}|9999999[0-8][0-9]{5}|99999999[0-8][0-9]{4}|999999999[0-8][0-9]{3}|9999999999[0-8][0-9]{2}|99999999999[0-8][0-9]|999999999999[0-9]|[1-8][0-9]{13}|9[0-8][0-9]{12}|99[0-8][0-9]{11}|999[0-8][0-9]{10}|9999[0-8][0-9]{9}|99999[0-8][0-9]{8}|999999[0-8][0-9]{7}|9999999[0-8][0-9]{6}|99999999[0-8][0-9]{5}|999999999[0-8][0-9]{4}|9999999999[0-8][0-9]{3}|99999999999[0-8][0-9]{2}|999999999999[0-8][0-9]|9999999999999[0-9]|[1-8][0-9]{14}|9[0-8][0-9]{13}|99[0-8][0-9]{12}|999[0-8][0-9]{11}|9999[0-8][0-9]{10}|99999[0-8][0-9]{9}|999999[0-8][0-9]{8}|9999999[0-8][0-9]{7}|99999999[0-8][0-9]{6}|999999999[0-8][0-9]{5}|9999999999[0-8][0-9]{4}|99999999999[0-8][0-9]{3}|999999999999[0-8][0-9]{2}|9999999999999[0-8][0-9]|99999999999999[0-9]|[1-8][0-9]{15}|9[0-8][0-9]{14}|99[0-8][0-9]{13}|999[0-8][0-9]{12}|9999[0-8][0-9]{11}|99999[0-8][0-9]{10}|999999[0-8][0-9]{9}|9999999[0-8][0-9]{8}|99999999[0-8][0-9]{7}|999999999[0-8][0-9]{6}|9999999999[0-8][0-9]{5}|99999999999[0-8][0-9]{4}|999999999999[0-8][0-9]{3}|9999999999999[0-8][0-9]{2}|99999999999999[0-8][0-9]|999999999999999[0-9]|[1-8][0-9]{16}|9[0-8][0-9]{15}|99[0-8][0-9]{14}|999[0-8][0-9]{13}|9999[0-8][0-9]{12}|99999[0-8][0-9]{11}|999999[0-8][0-9]{10}|9999999[0-8][0-9]{9}|99999999[0-8][0-9]{8}|999999999[0-8][0-9]{7}|9999999999[0-8][0-9]{6}|99999999999[0-8][0-9]{5}|999999999999[0-8][0-9]{4}|9999999999999[0-8][0-9]{3}|99999999999999[0-8][0-9]{2}|999999999999999[0-8][0-9]|9999999999999999[0-9]|[1-8][0-9]{17}|9[0-8][0-9]{16}|99[0-8][0-9]{15}|999[0-8][0-9]{14}|9999[0-8][0-9]{13}|99999[0-8][0-9]{12}|999999[0-8][0-9]{11}|9999999[0-8][0-9]{10}|99999999[0-8][0-9]{9}|999999999[0-8][0-9]{8}|9999999999[0-8][0-9]{7}|99999999999[0-8][0-9]{6}|999999999999[0-8][0-9]{5}|9999999999999[0-8][0-9]{4}|99999999999999[0-8][0-9]{3}|999999999999999[0-8][0-9]{2}|9999999999999999[0-8][0-9]|99999999999999999[0-9]|[1-8][0-9]{18}|9[01][0-9]{17}|92[01][0-9]{16}|922[0-2][0-9]{15}|9223[0-2][0-9]{14}|92233[0-6][0-9]{13}|922337[01][0-9]{12}|92233720[0-2][0-9]{10}|922337203[0-5][0-9]{9}|9223372036[0-7][0-9]{8}|92233720368[0-4][0-9]{7}|922337203685[0-3][0-9]{6}|9223372036854[0-6][0-9]{5}|92233720368547[0-6][0-9]{4}|922337203685477[0-4][0-9]{3}|9223372036854775[0-7][0-9]{2}|922337203685477580[0-7]))|0))$/D';
16
17
18
    /**
19
     * @param string $value
20
     * @param string $message
21
     */
22
    protected static function validLong(string $value, string $message = ''): void
23
    {
24
        parent::regex(
25
            $value,
26
            self::$long_regex,
27
            $message ?: '%s is not a valid xs:long',
28
            InvalidArgumentException::class,
29
        );
30
    }
31
}
32