Test Failed
Push — master ( f47101...348e9e )
by Ricardo
02:03
created

Name::toDatabase()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Validate;
4
5
use Validate\Traits\FakeNameTrait;
6
7
class Name implements \Validate\Contracts\Validate
8
{
9
    use FakeNameTrait;
10
11
    public static function toDatabase(string $fullName)
12
    {
13
        return strtoupper($fullName);
14
    }
15
16
    public static function toUser($fullName)
17
    {
18
        return $fullName;
19
    }
20
21
    public static function validate($fullName)
22
    {
23
        $name = self::break($fullName);
24
25
        if ($name['sobrenomes'] < 1) {
26
            return false;
27
        }
28
29
        if (static::incluiInArray($name['full'], static::$notPermit)) {
30
            return false;
31
        }
32
33
        if (static::incluiInArray($name['first'], static::$notPermitInFirst)) {
34
            return false;
35
        }
36
37
        if (filter_var($name['full'], FILTER_SANITIZE_NUMBER_INT) !== '') {
38
            return false;
39
        }
40
41
        return true;
42
    }
43
44
    public static function break($fullName)
45
    {
46
        $fullName = self::toDatabase($fullName);
47
        $nomes = explode(" ", trim($fullName));
48
        return [
49
            'first' => $nomes[0],
50
            'names' => $nomes,
51
            'full' => $fullName,
52
            'last' => $nomes[count($nomes)-1],
53
            'sobrenomes' => count($nomes)-1
54
        ];
55
    }
56
57
    public static function isSame(string $to, string $from)
58
    {
59
        $toBreak = self::break($to);
60
        $fromBreak = self::break($from);
61
        $to = self::toDatabase($to);
62
        $from = self::toDatabase($from);
63
        if ($to === $from) {
64
            return true;
65
        }
66
        if ($toBreak['first'] === $fromBreak['first'] && $toBreak['last'] === $fromBreak['last']) {
67
            return true;
68
        }
69
        return false;
70
    }
71
72
}
73