ByteTrait   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 39
rs 10
c 0
b 0
f 0
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A validByte() 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 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