Passed
Push — heiglandreas-patch-1 ( 7985cb...7bb7cc )
by Andreas
03:20
created

User   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 136
Duplicated Lines 0 %

Test Coverage

Coverage 40.74%

Importance

Changes 6
Bugs 0 Features 0
Metric Value
eloc 37
c 6
b 0
f 0
dl 0
loc 136
ccs 11
cts 27
cp 0.4074
rs 10
wmc 9

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getGender() 0 3 1
A setBirthday() 0 3 1
A getBirthday() 0 3 1
A setSex() 0 4 1
A getSex() 0 4 1
A setGender() 0 22 4
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_deprecated';
15
    
16
    /**
17
     * @deprecated Use GENDER_FEMALE instead!
18
     */
19
    const SEX_FEMALE = 'female_deprecated';
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 2
    public function getGender(): string
98
    {
99 2
        return $this->gender;
100
    }
101
102
    /**
103
     * @param string $sex
104
     */
105 3
    public function setGender(string $gender): void
106
    {
107 3
        if ($gender === self::SEX_MALE) {
0 ignored issues
show
Deprecated Code introduced by
The constant SocialConnect\Common\Entity\User::SEX_MALE has been deprecated: Use GENDER_MALE instead! ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

107
        if ($gender === /** @scrutinizer ignore-deprecated */ self::SEX_MALE) {

This class constant has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.

Loading history...
108
            trigger_error ('the constant SEX_MALE is deprecated. use GENDER_MALE instead', E_USER_DEPRECATED);
109
            $gender = self::GENDER_MALE;
110
        }
111
        
112 3
        if ($gender === self::SEX_FEMALE) {
0 ignored issues
show
Deprecated Code introduced by
The constant SocialConnect\Common\Entity\User::SEX_FEMALE has been deprecated: Use GENDER_FEMALE instead! ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

112
        if ($gender === /** @scrutinizer ignore-deprecated */ self::SEX_FEMALE) {

This class constant has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.

Loading history...
113
            trigger_error ('the constant SEX_FEMALE is deprecated. use GENDER_FEMALE instead', E_USER_DEPRECATED);
114
            $gender = self::GENDER_FEMALE;
115
        }
116
            
117
        $genders = [
118 3
            self::GENDER_OTHER,
119 3
            self::GENDER_MALE,
120 3
            self::GENDER_FEMALE,
121
        ];
122 3
        if (! in_array($gender, $genders)) {
123
            throw new \InvalidArgumentException('Argument $gender is not valid');
124
        }
125
126 3
        $this->gender = $gender;
127 3
    }
128
    
129
    /**
130
     * @deprecated use `getGender` instead
131
     */
132
    public function getSex() : string
133
    {
134
        trigger_error('getSex is deprecated. Use getGender instead', E_USER_DEPRECATED);
135
        return $this->getGender();
136
    }
137
    
138
    /**
139
     * @deprecated Use setGender instead
140
     */
141
    public function setSex(string $sex) : void
142
    {
143
        trigger_error('setSex is deprecated. Use setGender instead', E_USER_DEPRECATED);
144
        $this->setGender($sex);
145
    }
146
}
147