Fullname::check()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 5
c 1
b 0
f 0
nc 3
nop 1
dl 0
loc 13
ccs 0
cts 3
cp 0
crap 12
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 Fullname extends AbstractRule
15
{
16
    /**
17
     * Check if the given value is a valid fullname
18
     *
19
     * A string should represent a full name (at least 6 characters, at least 2 word, each word at least 2 characters long)
20
     *
21
     * @credit <a href="https://github.com/siriusphp/validation">siriusphp/validation - Sirius\Validation\Rule\FullName</a>
22
     *
23
     * This is not going to work with Asian names, http://en.wikipedia.org/wiki/Chinese_name.
24
     *
25
     * @param mixed $value
26
     */
27
    public function check($value): bool
28
    {
29
        $names = explode(' ', $value);
30
31
        // Each name must be at least 2 characters long.
32
        foreach ($names as $name) {
33
            if (mb_strlen($name) < 2) {
34
                return false;
35
            }
36
        }
37
38
        // Name cannot be longer shorter than 6 characters.
39
        return mb_strlen($value) >= 6;
40
    }
41
}
42