UuidValidation::isUuidValid()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 1
1
<?php
2
declare(strict_types = 1);
3
4
namespace AmmitPhp\Ammit\Domain;
5
6
class UuidValidation
7
{
8
    /**
9
     * Valid against UUID format
10
     * @param string $string String to validate
11
     * @return bool
12
     */
13
    public function isUuidValid(string $string): bool
14
    {
15
        if ($this->isValidUuidAgainstRegex($string)) {
0 ignored issues
show
Unused Code introduced by
This if statement, and the following return statement can be replaced with return $this->isValidUuidAgainstRegex($string);.
Loading history...
16
            return true;
17
        }
18
19
        return false;
20
    }
21
22
    private function isValidUuidAgainstRegex($string): bool
23
    {
24
        if (preg_match('/^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$/', $string)) {
0 ignored issues
show
Unused Code introduced by
This if statement, and the following return statement can be replaced with return (bool) preg_match...Fa-f]{12}$/', $string);.
Loading history...
25
            return true;
26
        }
27
28
        return false;
29
    }
30
}
31