From 71b7bdea9bb7404ea9d838a780c093d027114467 Mon Sep 17 00:00:00 2001 From: Bill li Date: Sun, 19 Nov 2017 13:39:43 +0800 Subject: [PATCH] fix bug. --- src/IdentityCard.php | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/src/IdentityCard.php b/src/IdentityCard.php index 120de56..f069cd3 100644 --- a/src/IdentityCard.php +++ b/src/IdentityCard.php @@ -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']; } /** @@ -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']; } /** @@ -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'; } /**