GuidValue::validate()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 3
nc 2
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Linio\Component\Input\Constraint;
6
7
class GuidValue extends Constraint
8
{
9
    const ERROR_MESSAGE = 'Invalid GUID format';
10
11
    public function __construct(string $errorMessage = null)
12
    {
13
        $this->setErrorMessage($errorMessage ?? static::ERROR_MESSAGE);
14
    }
15
16
    public function validate($content): bool
17
    {
18
        if (!is_string($content) || strlen($content) != 36) {
19
            return false;
20
        }
21
22
        return (bool) preg_match('/^[0-9a-fA-F]{8}\-([0-9a-fA-F]{4}\-){3}[0-9a-fA-F]{12}$/', $content);
23
    }
24
}
25