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

AlphaNumHyphen::validate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 17
ccs 8
cts 8
cp 1
rs 9.7
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 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