Skip to content

Commit

Permalink
Replace get/setSex with get/setGender
Browse files Browse the repository at this point in the history
As explained in #94 it's a good idea to use gender instead of sex. 

To not break BC the get/setSex are still available but are marked as deprecated. The current functionality works as before. In addition to that it is possible to set `other` as gender and the default now is to return `unknown` instead of NULL.
  • Loading branch information
heiglandreas authored Sep 15, 2019
1 parent 4872935 commit 8f43775
Showing 1 changed file with 35 additions and 12 deletions.
47 changes: 35 additions & 12 deletions src/Common/Entity/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@

class User extends \stdClass
{
const SEX_MALE = 'male';
const SEX_FEMALE = 'female';
const GENDER_MALE = 'male';
const GENDER_FEMALE = 'female';
const GENDER_OTHER = 'other';
const GENDER_UNKNOWN = 'unknown';

/**
* @var string
Expand Down Expand Up @@ -47,11 +49,11 @@ class User extends \stdClass
public $username;

/**
* Should be female or male
* One of the GENDER_-constants
*
* @var string|null
* @var string
*/
protected $sex;
protected $gender = GENDER_UNKNOWN;

/**
* @var string|null
Expand Down Expand Up @@ -80,22 +82,43 @@ public function setBirthday(?\DateTime $birthday): void
}

/**
* @return string|null
* @return string
*/
public function getSex(): ?string
public function getGender(): string
{
return $this->sex;
return $this->gender;
}

/**
* @param string $sex
*/
public function setSex(string $sex): void
public function setGender(string $gender): void
{
if ($sex !== self::SEX_MALE && $sex !== self::SEX_FEMALE) {
throw new \InvalidArgumentException('Argument $sex is not valid');
$genders = [
GENDER_OTHER,
GENDER_MALE,
GENDER_FEMALE,
];
if (! $gender in_array($genders)) {
throw new \InvalidArgumentException('Argument $gender is not valid');
}

$this->sex = $sex;
$this->gender = $gender;
}

/**
* @deprecated use `getGender` instead
*/
public function getSex() : string
{
return $this->getGender();
}

/**
* @deprecated Use setGender instead
*/
public function setSex(string $sex) : void
{
$this->setGender($sex);
}
}

0 comments on commit 8f43775

Please sign in to comment.