Gender   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 0

Importance

Changes 0
Metric Value
wmc 8
lcom 2
cbo 0
dl 0
loc 43
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 2
A random() 0 4 1
A male() 0 4 1
A female() 0 4 1
A isMale() 0 4 1
A isFemale() 0 4 1
A __toString() 0 4 1
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