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
|
|
|
|