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

Gender::isSame()   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 2
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 Gender implements \Validate\Contracts\Validate
8
{
9
    use FakeNameTrait;
10
    
11
    public static $toMale = [
12
        'MASCULINO',
13
        'HOMEM',
14
        'MALE',
15
        'MACHO'
16
    ];
17
    public static $toWoman = [
18
        'FEMININO',
19
        'MULHER',
20
        'WOMAN',
21
        'FEMIA'
22
    ];
23
24
    public static function toDatabase($gender)
25
    {
26
        return substr(((string) self::filter(strtoupper(preg_replace('/[^A-z]/', '',$gender)))), 0, 1);
27
    }
28
29
    public static function filter($gender) {
30
        if (static::incluiInArray($gender, static::$toMale)) {
31
            return 'MASCULINO';
32
        }
33
        if (static::incluiInArray($gender, static::$toWoman)) {
34
            return 'FEMININO';
35
        }
36
        return $gender;
37
    }
38
39
    public static function toUser($gender)
40
    {
41
        if($gender == 'M') {
42
            return 'Masculino';
43
        }
44
        
45
        if($gender == 'F') {
46
            return 'Feminino';
47
        }
48
        
49
        return 'Unissex';
50
    }
51
52
    public static function validate($gender)
53
    {
54
        $gender = self::toDatabase($gender);
55
56
        if ($gender !== 'U' && $gender !== 'M' && $gender !== 'F') {
57
            return false;
58
        }
59
60
        return true;
61
    }
62
63
    public static function isSame(string $to, string $from)
64
    {
65
        return (self::toDatabase($to)===self::toDatabase($from));
66
    }
67
68
}
69