IsUuid::check()   A
last analyzed

Complexity

Conditions 5
Paths 4

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 14
rs 9.6111
cc 5
nc 4
nop 1
1
<?php
2
/**
3
 * @author    Nurlan Mukhanov <[email protected]>
4
 * @copyright 2022 Nurlan Mukhanov
5
 * @license   https://en.wikipedia.org/wiki/MIT_License MIT License
6
 * @link      https://github.com/Falseclock/service-layer
7
 */
8
9
declare(strict_types=1);
10
11
namespace Falseclock\Service\Validation\Validators;
12
13
class IsUuid extends IsString
14
{
15
    /**
16
     * @param null $value
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $value is correct as it would always require null to be passed?
Loading history...
17
     * @return bool
18
     * @noinspection RegExpSimplifiable
19
     */
20
    public function check($value = null): bool
21
    {
22
        if (!parent::check($value)) {
23
            return false;
24
        }
25
26
        if (is_null($value) && $this->nullable) {
27
            return true;
28
        }
29
30
        if ((preg_match('/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/', (string)$value) !== 1))
31
            return false;
32
33
        return true;
34
    }
35
}
36