Gender::random()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Gimei;
4
5
class Gender
6
{
7
    const MALE = 'male';
8
    const FEMALE = 'female';
9
10
    protected $gender = null;
11
12
    public function __construct($gender = null)
13
    {
14
        $genders = [self::MALE, self::FEMALE];
15
        $this->gender = $gender ?: $genders[array_rand($genders)];
16
    }
17
18
    public static function random()
19
    {
20
        return new self();
21
    }
22
23
    public static function male()
24
    {
25
        return new self(self::MALE);
26
    }
27
28
    public static function female()
29
    {
30
        return new self(self::FEMALE);
31
    }
32
33
    public function isMale()
34
    {
35
        return $this->gender === self::MALE;
36
    }
37
38
    public function isFemale()
39
    {
40
        return $this->gender === self::FEMALE;
41
    }
42
43
    public function __toString()
44
    {
45
        return $this->gender;
46
    }
47
}
48