Fullname   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 1 Features 0
Metric Value
eloc 6
c 2
b 1
f 0
dl 0
loc 26
ccs 0
cts 3
cp 0
rs 10
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A check() 0 13 3
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