Passed
Push — heiglandreas-patch-1 ( 8b9b12...3c2950 )
by Andreas
05:14 queued 03:50
created

User::setGender()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 7
nc 2
nop 1
dl 0
loc 12
ccs 0
cts 7
cp 0
crap 6
rs 10
c 1
b 0
f 0
1
<?php
2
/**
3
 * SocialConnect project
4
 * @author: Patsura Dmitry @ovr <[email protected]>
5
 */
6
7
namespace SocialConnect\Common\Entity;
8
9
class User extends \stdClass
10
{
11
    /**
12
     * @deprecated Use GENDER_MALE instead!
13
     */
14
    const SEX_MALE = 'male';
15
    
16
    /**
17
     * @deprecated Use GENDER_FEMALE instead!
18
     */
19
    const SEX_FEMALE = 'female';
20
    
21
    const GENDER_MALE = 'male';
22
    const GENDER_FEMALE = 'female';
23
    const GENDER_OTHER = 'other';
24
    const GENDER_UNKNOWN = 'unknown';
25
26
    /**
27
     * @var string
28
     */
29
    public $id;
30
31
    /**
32
     * @var string
33
     */
34
    public $firstname;
35
36
    /**
37
     * @var string
38
     */
39
    public $lastname;
40
41
    /**
42
     * @var string
43
     */
44
    public $email;
45
46
    /**
47
     * @var bool
48
     */
49
    public $emailVerified = false;
50
51
    /**
52
     * @var \DateTime|null
53
     */
54
    protected $birthday;
55
56
    /**
57
     * @var string|null
58
     */
59
    public $username;
60
61
    /**
62
     * One of the GENDER_-constants
63
     *
64
     * @var string
65
     */
66
    protected $gender = self::GENDER_UNKNOWN;
67
68
    /**
69
     * @var string|null
70
     */
71
    public $fullname;
72
73
    /**
74
     * @var string|null
75
     */
76
    public $pictureURL;
77
78
    /**
79
     * @return \DateTime|null
80
     */
81
    public function getBirthday(): ?\DateTime
82
    {
83
        return $this->birthday;
84
    }
85
86
    /**
87
     * @param \DateTime|null $birthday
88
     */
89
    public function setBirthday(?\DateTime $birthday): void
90
    {
91
        $this->birthday = $birthday;
92
    }
93
94
    /**
95
     * @return string
96
     */
97
    public function getGender(): string
98
    {
99
        return $this->gender;
100
    }
101
102
    /**
103
     * @param string $sex
104
     */
105
    public function setGender(string $gender): void
106
    {
107
        $genders = [
108
            self::GENDER_OTHER,
109
            self::GENDER_MALE,
110
            self::GENDER_FEMALE,
111
        ];
112
        if (! in_array($gender, $genders)) {
113
            throw new \InvalidArgumentException('Argument $gender is not valid');
114
        }
115
116
        $this->gender = $gender;
117
    }
118
    
119
    /**
120
     * @deprecated use `getGender` instead
121
     */
122
    public function getSex() : string
123
    {
124
        trigger_error('getSex is deprecated. Use getGender instead', E_USER_DEPRECATED);
125
        return $this->getGender();
126
    }
127
    
128
    /**
129
     * @deprecated Use setGender instead
130
     */
131
    public function setSex(string $sex) : void
132
    {
133
        trigger_error('setSex is deprecated. Use setGender instead', E_USER_DEPRECATED);
134
        $this->setGender($sex);
135
    }
136
}
137