AlphaNumericRule::validateClean()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Bluz Framework Component
5
 *
6
 * @copyright Bluz PHP Team
7
 * @link      https://github.com/bluzphp/framework
8
 */
9
10
declare(strict_types=1);
11
12
namespace Bluz\Validator\Rule;
13
14
/**
15
 * Check for alphanumeric character(s)
16
 *
17
 * @package Bluz\Validator\Rule
18
 */
19
class AlphaNumericRule extends AbstractCtypeRule
20
{
21
    /**
22
     * Check for alphanumeric character(s)
23
     *
24
     * @param string $input
25
     *
26
     * @return bool
27
     */
28 23
    protected function validateClean($input): bool
29
    {
30 23
        return ctype_alnum($input);
31
    }
32
33
    /**
34
     * Get error template
35
     *
36
     * @return string
37
     */
38 25
    public function getDescription(): string
39
    {
40 25
        if (empty($this->additionalChars)) {
41 20
            return __('must contain only Latin letters and digits');
42
        }
43 6
        return __('must contain only Latin letters, digits and "%s"', $this->additionalChars);
44
    }
45
}
46