Uuid   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 1
dl 0
loc 39
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B __invoke() 0 25 3
1
<?php
2
/**
3
 *
4
 * This file is part of Aura for PHP.
5
 *
6
 * @license http://opensource.org/licenses/bsd-license.php BSD
7
 *
8
 */
9
namespace Aura\Filter\Rule\Sanitize;
10
11
use Aura\Filter\Rule\AbstractUuid;
12
13
/**
14
 *
15
 * Forces the value to a canonical UUID.
16
 *
17
 * @package Aura.Filter
18
 *
19
 */
20
class Uuid extends AbstractUuid
21
{
22
    /**
23
     *
24
     * Forces the value to a canonical UUID.
25
     *
26
     * @param object $subject The subject to be filtered.
27
     *
28
     * @param string $field The subject field name.
29
     *
30
     * @return bool True if the value was sanitized, false if not.
31
     *
32
     */
33 7
    public function __invoke($subject, $field)
34
    {
35 7
        $value = $subject->$field;
36 7
        if ($this->isCanonical($value)) {
37
            // already a canonical value
38 1
            return true;
39
        }
40
41
        // force to hex only
42 6
        $value = preg_replace('/[^a-f0-9]/i', '', $subject->$field);
43 6
        if (! $this->isHexOnly($value)) {
44
            // not hex-only, cannot sanitize
45 2
            return false;
46
        }
47
48
        // add the dashes
49 4
        $subject->$field = substr($value, 0, 8) . '-'
50 4
                         . substr($value, 8, 4) . '-'
51 4
                         . substr($value, 12, 4) . '-'
52 4
                         . substr($value, 16, 4) . '-'
53 4
                         . substr($value, 20);
54
55
        // done!
56 4
        return true;
57
     }
58
}
59