Completed
Push — master ( f5c89e...6e16e6 )
by Adrian
02:13
created

AlphaNumHyphen   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 1
lcom 1
cbo 1
dl 0
loc 23
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A validate() 0 17 1
1
<?php
2
declare(strict_types=1);
3
namespace Sirius\Validation\Rule;
4
5
class AlphaNumHyphen extends AbstractRule
6
{
7
    const MESSAGE = 'This input must contain only letters, digits, spaces, hyphens and underscores';
8
    const LABELED_MESSAGE = '{label} must contain only letters, digits, spaces, hyphens and underscores';
9
10 1
    public function validate($value, string $valueIdentifier = null):bool
11
    {
12 1
        $this->value   = $value;
13 1
        $this->success = (bool) ctype_alnum(
14 1
            (string) str_replace(
15
                [
16 1
                    ' ',
17
                    '_',
18
                    '-'
19
                ],
20 1
                '',
21 1
                $value
22
            )
23
        );
24
25 1
        return $this->success;
26
    }
27
}
28