GuidValue   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 1
dl 0
loc 18
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A validate() 0 8 3
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