ByteTrait::validByte()   A
last analyzed

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