Isbn   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
class Isbn implements SanitizeRuleInterface
6
{
7
    /**
8
     * Forces the value to an ISBN.
9
     *
10
     * @param object $subject The subject to be filtered.
11
     * @param string $field The subject field name.
12
     *
13
     * @return bool True if the value was sanitized, false if not.
14
     */
15 15
    public function __invoke($subject, string $field): bool
16
    {
17 15
        $value = preg_replace('/(?:(?!([0-9|X$])).)*/', '', $subject->$field);
18 15
        if (preg_match('/^[0-9]{10,13}$|^[0-9]{9}X$/', $value) == 1) {
19 9
            $subject->$field = $value;
20
21 9
            return true;
22
        }
23
24 6
        return false;
25
    }
26
}
27