Gender::isSame()   A
last analyzed

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\GetDataTrait;
6
7
class Gender implements \Validate\Contracts\Validate
8
{
9
    use GetDataTrait;
10
11
    public static function toDatabase($gender)
12
    {
13
        return substr(((string) self::filter(strtoupper(preg_replace('/[^A-z]/', '', $gender)))), 0, 1);
14
    }
15
16
    public static function filter(string $gender)
17
    {
18
        if (static::foundInFile($gender, 'gender-names-to-male')) {
19
            return 'MASCULINO';
20
        }
21
        if (static::foundInFile($gender, 'gender-names-to-woman')) {
22
            return 'FEMININO';
23
        }
24
        return $gender;
25
    }
26
27
    public static function toUser($gender)
28
    {
29
        if($gender == 'M') {
30
            return 'Masculino';
31
        }
32
        
33
        if($gender == 'F') {
34
            return 'Feminino';
35
        }
36
        
37
        return 'Unissex';
38
    }
39
40
    public static function validate($gender)
41
    {
42
        $gender = self::toDatabase($gender);
43
44
        if ($gender !== 'U' && $gender !== 'M' && $gender !== 'F') {
45
            return false;
46
        }
47
48
        return true;
49
    }
50
51
    public static function isSame(string $to, string $from)
52
    {
53
        return (self::toDatabase($to)===self::toDatabase($from));
54
    }
55
56
}
57