ShortTrait::validShort()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 1
nop 2
dl 0
loc 7
rs 10
c 0
b 0
f 0
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 ShortTrait
13
{
14
    private static string $short_regex = '/^
15
        (
16
            (
17
                ([+-]?0*)
18
                (?:
19
                    [1-9]
20
                    |3276[0-7]
21
                    |[1-9][0-9]
22
                    |[1-9][0-9][0-9]
23
                    |[1-9][0-9][0-9][0-9]
24
                    |[12][0-9][0-9][0-9][0-9]
25
                    |3[01][0-9][0-9][0-9]
26
                    |32[0-6][0-9][0-9]
27
                    |327[0-5][0-9]
28
                    |[0-9]
29
                    |3276[0-7]
30
                )
31
            )
32
            |0
33
            |((-0*)32768)
34
        )
35
        $/Dx';
36
37
38
    /**
39
     * @param string $value
40
     * @param string $message
41
     */
42
    protected static function validShort(string $value, string $message = ''): void
43
    {
44
        parent::regex(
45
            $value,
46
            self::$short_regex,
47
            $message ?: '%s is not a valid xs:short',
48
            InvalidArgumentException::class,
49
        );
50
    }
51
}
52