Gender   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 18
c 1
b 0
f 0
dl 0
loc 47
rs 10
wmc 12

5 Methods

Rating   Name   Duplication   Size   Complexity  
A toDatabase() 0 3 1
A filter() 0 9 3
A validate() 0 9 4
A toUser() 0 11 3
A isSame() 0 3 1
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