Name   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 80
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 22
c 1
b 0
f 0
dl 0
loc 80
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A isNotMale() 0 3 1
A isMale() 0 3 1
A isNotFemale() 0 3 1
A prepareData() 0 11 1
A isFemale() 0 3 1
1
<?php
2
3
namespace Pixelpeter\Genderize\Models;
4
5
class Name extends BaseModel
6
{
7
    protected $gender;
8
9
    protected $name;
10
11
    protected $probability;
12
13
    protected $count;
14
15
    /**
16
     * Create new instance of Name model
17
     */
18
    public function __construct($data)
19
    {
20
        $data = $this->prepareData($data);
21
22
        $this->name = $data->name;
23
        $this->gender = $data->gender;
24
        $this->probability = $data->probability;
25
        $this->count = $data->count;
26
    }
27
28
    /**
29
     * Merge data with default so every field is available
30
     *
31
     * @return object
32
     */
33
    protected function prepareData($data)
34
    {
35
        $default = new \StdClass;
36
        $default->name = null;
37
        $default->gender = null;
38
        $default->probability = null;
39
        $default->count = null;
40
41
        return (object) array_merge(
42
            (array) $default,
43
            (array) $data
44
        );
45
    }
46
47
    /**
48
     * Check if name is male
49
     *
50
     * @return bool
51
     */
52
    public function isMale()
53
    {
54
        return $this->gender === 'male';
55
    }
56
57
    /**
58
     * Check if name is not male
59
     *
60
     * @return bool
61
     */
62
    public function isNotMale()
63
    {
64
        return $this->gender !== 'male';
65
    }
66
67
    /**
68
     * Check if name is female
69
     *
70
     * @return bool
71
     */
72
    public function isFemale()
73
    {
74
        return $this->gender === 'female';
75
    }
76
77
    /**
78
     * Check if name is not female
79
     *
80
     * @return bool
81
     */
82
    public function isNotFemale()
83
    {
84
        return $this->gender !== 'female';
85
    }
86
}
87