Uuid::getMessage()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 5
nc 3
nop 2
dl 0
loc 11
ccs 6
cts 6
cp 1
crap 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace Hop\Validator\Validator;
6
7
class Uuid implements RuleValidator
8
{
9
    use IsValidTrait;
10
11
    /**
12
     * @inheritdoc
13
     */
14 3
    public function getMessage($value, ?array $options)
15
    {
16 3
        if (!\is_scalar($value)) {
17 1
            return 'Param is not scalar';
18
        }
19
20 2
        if (!preg_match('/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i', (string)$value)) {
21 1
            return 'Pattern does not match UUID';
22
        }
23
24 1
        return null;
25
    }
26
}
27