Word::__invoke()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 2
dl 0
loc 9
ccs 6
cts 6
cp 1
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Mbright\Validation\Rule\Sanitize;
4
5
class Word implements SanitizeRuleInterface
6
{
7
    /**
8
     * Strips non-word characters within the value (letters, numbers, and
9
     * underscores).
10
     *
11
     * @param object $subject The subject to be filtered.
12
     * @param string $field The subject field name.
13
     *
14
     * @return bool True if the value was sanitized, false if not.
15
     */
16 9
    public function __invoke($subject, string $field): bool
17
    {
18 9
        $value = $subject->$field;
19 9
        if (!is_scalar($value)) {
20 3
            return false;
21
        }
22 6
        $subject->$field = preg_replace('/[^\p{L}\p{Nd}_]/u', '', $value);
23
24 6
        return true;
25
    }
26
}
27