UuidHexOnly   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 20
ccs 6
cts 6
cp 1
rs 10
c 0
b 0
f 0
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 10 2
1
<?php
2
3
namespace Mbright\Validation\Rule\Sanitize;
4
5
use Mbright\Validation\Rule\AbstractUuidCase;
6
7
class UuidHexOnly extends AbstractUuidCase implements SanitizeRuleInterface
8
{
9
    /**
10
     * Forces the value to a hex-only UUID.
11
     *
12
     * @param object $subject The subject to be filtered.
13
     * @param string $field The subject field name.
14
     *
15
     * @return bool True if the value was sanitized, false if not.
16
     */
17 15
    public function __invoke($subject, string $field): bool
18
    {
19 15
        $value = preg_replace('/[^a-f0-9]/i', '', $subject->$field);
20 15
        if ($this->isHexOnly($value)) {
21 9
            $subject->$field = $value;
22
23 9
            return true;
24
        }
25
26 6
        return false;
27
    }
28
}
29