ByteTrait::validByte()   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 ByteTrait
13
{
14
    private static string $byte_regex = '/^
15
        (
16
            (
17
                (
18
                    -[0]*
19
                    (
20
                        [0-9]
21
                        |[1-8]\d
22
                        |9\d
23
                        |1[01]\d
24
                        |12[0-8]
25
                    )
26
                )|(
27
                    [+]?[0]*
28
                    (
29
                        [0-9]
30
                        |[1-8]\d
31
                        |9\d
32
                        |1[01]\d
33
                        |12[0-7]
34
                    )
35
                )|0
36
            )
37
        )$/Dx';
38
39
40
    /**
41
     * @param string $value
42
     * @param string $message
43
     */
44
    protected static function validByte(string $value, string $message = ''): void
45
    {
46
        parent::regex(
47
            $value,
48
            self::$byte_regex,
49
            $message ?: '%s is not a valid xs:byte',
50
            InvalidArgumentException::class,
51
        );
52
    }
53
}
54