Name   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 34
c 1
b 0
f 0
dl 0
loc 71
rs 10
wmc 11

5 Methods

Rating   Name   Duplication   Size   Complexity  
A toDatabase() 0 3 1
A toUser() 0 3 1
A validate() 0 29 4
A isSame() 0 13 4
A break() 0 10 1
1
<?php
2
3
namespace Validate;
4
5
use Validate\Traits\BlockStringTrait;
6
use Validate\Traits\GetDataTrait;
7
8
class Name implements \Validate\Contracts\Validate
9
{
10
    use BlockStringTrait, GetDataTrait;
11
12
    public static function toDatabase(string $fullName)
13
    {
14
        return strtoupper($fullName);
15
    }
16
17
    public static function toUser($fullName)
18
    {
19
        return $fullName;
20
    }
21
22
    public static function validate($fullName)
23
    {
24
        $name = self::break($fullName);
25
26
        if ($name['sobrenomes'] < 1) {
27
            return false;
28
        }
29
30
        if (self::foundInMultiplesArrays(
31
            [
32
            [
33
                $name['full'],
34
                self::getListFromFile('black-names')
35
            ],
36
            [
37
                $name['first'],
38
                self::getListFromFile('black-first-names')
39
            ],
40
            ]
41
        )
42
        ) {
43
            return false;
44
        }
45
46
        if (filter_var($name['full'], FILTER_SANITIZE_NUMBER_INT) !== '') {
47
            return false;
48
        }
49
50
        return true;
51
    }
52
53
    public static function break(string $fullName)
54
    {
55
        $fullName = self::toDatabase($fullName);
56
        $nomes = explode(" ", trim($fullName));
57
        return [
58
            'first' => $nomes[0],
59
            'names' => $nomes,
60
            'full' => $fullName,
61
            'last' => $nomes[count($nomes)-1],
62
            'sobrenomes' => count($nomes)-1
63
        ];
64
    }
65
66
    public static function isSame(string $to, string $from)
67
    {
68
        $toBreak = self::break($to);
69
        $fromBreak = self::break($from);
70
        $to = self::toDatabase($to);
71
        $from = self::toDatabase($from);
72
        if ($to === $from) {
73
            return true;
74
        }
75
        if ($toBreak['first'] === $fromBreak['first'] && $toBreak['last'] === $fromBreak['last']) {
76
            return true;
77
        }
78
        return false;
79
    }
80
81
}
82