Word   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 0
dl 0
loc 24
ccs 6
cts 6
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 9 2
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\AbstractStrlen;
12
13
/**
14
 *
15
 * Strips non-word characters within the value.
16
 *
17
 * @package Aura.Filter
18
 *
19
 */
20
class Word
21
{
22
    /**
23
     *
24
     * Strips non-word characters within the value (letters, numbers, and
25
     * underscores).
26
     *
27
     * @param object $subject The subject to be filtered.
28
     *
29
     * @param string $field The subject field name.
30
     *
31
     * @return bool True if the value was sanitized, false if not.
32
     *
33
     */
34 3
    public function __invoke($subject, $field)
35
    {
36 3
        $value = $subject->$field;
37 3
        if (! is_scalar($value)) {
38 1
            return false;
39
        }
40 2
        $subject->$field = preg_replace('/[^\p{L}\p{Nd}_]/u', '', $value);
41 2
        return true;
42
    }
43
}
44