AlphaNum::check()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 5
c 1
b 0
f 0
nc 3
nop 1
dl 0
loc 11
ccs 3
cts 3
cp 1
crap 4
rs 10
1
<?php
2
3
/**
4
 * This file is part of Dimtrovich/Validation.
5
 *
6
 * (c) 2023 Dimitri Sitchet Tomkeu <[email protected]>
7
 *
8
 * For the full copyright and license information, please view
9
 * the LICENSE file that was distributed with this source code.
10
 */
11
12
namespace Dimtrovich\Validation\Rules;
13
14
class AlphaNum extends AbstractRule
15
{
16
    protected $fillableParams = ['mode'];
17
18
    /**
19
     * {@inheritDoc}
20
     */
21
    public function check($value): bool
22
    {
23
        if (! is_string($value) && ! is_numeric($value)) {
24 2
            return false;
25
        }
26
27
        if ($this->parameter('mode') === 'ascii') {
28 2
            return preg_match('/\A[a-zA-Z0-9]+\z/u', $value) > 0;
29
        }
30
31 2
        return preg_match('/\A[\pL\pM\pN]+\z/u', $value) > 0;
32
    }
33
}
34