AbstractUuid::isCanonical()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 3
cts 3
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
crap 1
1
<?php
2
/**
3
 *
4
 * This file is part of Aura for PHP.
5
 *
6
 * @license http://opensource.org/licenses/bsd-license.php BSD
7
 *
8
 */
9
namespace Aura\Filter\Rule;
10
11
/**
12
 *
13
 * Abstract rule for Universally Unique Identifier (UUID) filters.
14
 *
15
 * @package Aura.Filter
16
 *
17
 */
18
abstract class AbstractUuid
19
{
20
    /**
21
     *
22
     * Does the value match the canonical UUID format?
23
     *
24
     * @param string $value The value to be checked.
25
     *
26
     * @return bool
27
     *
28
     */
29 21
    protected function isCanonical($value)
30
    {
31 21
        $regex = '/^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/i';
32 21
        return (bool) preg_match($regex, $value);
33
    }
34
35
    /**
36
     *
37
     * Is the value a hex-only UUID?
38
     *
39
     * @param string $value The value to be checked.
40
     *
41
     * @return bool
42
     *
43
     */
44 29
    protected function isHexOnly($value)
45
    {
46 29
        $regex = '/^[a-f0-9]{32}$/i';
47 29
        return (bool) preg_match($regex, $value);
48
    }
49
}
50