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

LongTrait   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 16
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 16
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 = '/^(([-+]?[0]*)?(?:[1-9]|[1-9]\d{1,14}|1000000000000000|1000000000000000[1-9]|10000000000000000[1-9]|[1-8][1-9]\d{17}|9[01]\d{17}|92[01]\d{16}|922[0-2]\d{15}|9223[0-2]\d{14}|92233[0-6]\d{13}|922337[01]\d{12}|92233720[0-2]\d{10}|922337203[0-5]\d{9}|9223372036[0-7]\d{8}|92233720368[0-4]\d{7}|922337203685[0-3]\d{6}|9223372036854[0-6]\d{5}|92233720368547[0-6]\d{4}|922337203685477[0-4]\d{3}|9223372036854775[0-7]\d{2}|922337203685477580[0-7])|0|(-([0]*)?)9223372036854775808)$/D';
16
17
    /**
18
     * @param string $value
19
     * @param string $message
20
     */
21
    protected static function validLong(string $value, string $message = ''): void
22
    {
23
        parent::regex(
24
            $value,
25
            self::$long_regex,
26
            $message ?: '%s is not a valid xs:long',
27
            InvalidArgumentException::class,
28
        );
29
    }
30
}
31