AbstractUuidCase::isCanonical()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 5
ccs 3
cts 3
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Mbright\Validation\Rule;
4
5
class AbstractUuidCase
6
{
7
    /**
8
     * Does the value match the canonical UUID format?
9
     *
10
     * @param string $value The value to be checked.
11
     *
12
     * @return bool
13
     */
14 63
    protected function isCanonical($value)
15
    {
16 63
        $regex = '/^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/i';
17
18 63
        return (bool) preg_match($regex, $value);
19
    }
20
21
    /**
22
     * Is the value a hex-only UUID?
23
     *
24
     * @param string $value The value to be checked.
25
     *
26
     * @return bool
27
     */
28 87
    protected function isHexOnly($value)
29
    {
30 87
        $regex = '/^[a-f0-9]{32}$/i';
31
32 87
        return (bool) preg_match($regex, $value);
33
    }
34
}
35