Skip to content

Commit

Permalink
fix bug.
Browse files Browse the repository at this point in the history
  • Loading branch information
Bill li committed Nov 19, 2017
1 parent 212d65e commit 71b7bde
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions src/IdentityCard.php
Original file line number Diff line number Diff line change
Expand Up @@ -24803,7 +24803,12 @@ public function getArea()
*/
public function getProvince() : ?string
{
return $this->regions[substr(static::$idCard, 0, 2).'0000'][static::locale] ?? null;
if ( !isset($province = $this->regions[substr(static::$idCard, 0, 2).'0000']) )
{
return null;
}

return $province[static::locale] ?? $province['zh-cn'];
}

/**
Expand All @@ -24813,7 +24818,12 @@ public function getProvince() : ?string
*/
public function getCity() : ?string
{
return $this->regions[substr(static::$idCard, 0, 4)][static::locale] ?? null;
if ( !isset($city = $this->regions[substr(static::$idCard, 0, 4)]) )
{
return null;
}

return $city[static::locale] ?? $city['zh-cn'];
}

/**
Expand All @@ -24823,24 +24833,22 @@ public function getCity() : ?string
*/
public function getCounty() : ?string
{
return $this->regions[substr(static::$idCard, 0, 6)][static::locale] ?? null;
if ( !isset($county = $this->regions[substr(static::$idCard, 0, 6)]) )
{
return null;
}

return $county[static::locale] ?? $county['zh-cn'];
}

/**
* Gender.
*
* @return string|bool
* @return string
*/
public function getGender()
public function getGender() : string
{
if ( $this->validateIDCard(static::$idCard) )
{
$gender = substr(static::$idCard, 16, 1);

return ($gender % 2 == 0) ? 'female' : 'male';
}

return false;
return (substr(static::$idCard, 16, 1) % 2 == 0) ? 'female' : 'male';
}

/**
Expand Down

0 comments on commit 71b7bde

Please sign in to comment.