AlphaDash   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 18
ccs 5
cts 5
cp 1
rs 10
c 0
b 0
f 0
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 8 3
1
<?php
2
3
namespace Mbright\Validation\Rule\Validate;
4
5
class AlphaDash implements ValidateRuleInterface
6
{
7
    /**
8
     * Validates that the specified field only contains alpha-numeric characters, dashes, and underscores.
9
     *
10
     * @param $subject
11
     * @param string $field
12
     *
13
     * @return bool
14
     */
15 27
    public function __invoke($subject, string $field): bool
16
    {
17 27
        $value = $subject->$field;
18 27
        if (!is_string($value) && !is_numeric($value)) {
19 6
            return false;
20
        }
21
22 21
        return preg_match('/^[\pL\pM\pN_-]+$/u', $value) > 0;
23
    }
24
}
25