Uuid::validate()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Softonic\OpenApi\Validation\Format;
4
5
use Opis\JsonSchema\IFormat;
6
7
/**
8
 * Class Uuid
9
 *
10
 * Basic validator created until the Respect validator is released.
11
 *
12
 * @see https://github.com/Respect/Validation/blob/master/library/Rules/Uuid.php
13
 */
14
final class Uuid implements IFormat
15
{
16
    const PATTERN_FORMAT = '/^[0-9a-f]{8}-[0-9a-f]{4}-[13-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i';
17
18
    /**
19
     * @param $data
20
     *
21
     * @return bool
22
     */
23 18
    public function validate($data): bool
24
    {
25 18
        return preg_match(self::PATTERN_FORMAT, $data) > 0;
26
    }
27
}
28