Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
lilianjin committed Apr 13, 2019
1 parent b4e7c44 commit e1e66b7
Showing 1 changed file with 17 additions and 26 deletions.
43 changes: 17 additions & 26 deletions src/IdentityCard.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ public static function make(string $idCard, string $locale = 'zh-cn')

static::$locale = in_array($locale, ['zh-cn', 'en']) ? $locale : 'zh-cn';

if ( static::check() === false )
{
if (static::check() === false) {
return false;
}

Expand All @@ -80,13 +79,11 @@ protected static function check() : bool
{
$id = strtoupper(static::$idCard);

if ( static::checkFirst($id) === true )
{
if (static::checkFirst($id) === true) {
$iYear = substr($id, 6, 4);
$iMonth = substr($id, 10, 2);
$iDay = substr($id, 12, 2);
if ( checkdate($iMonth, $iDay, $iYear) )
{
if (checkdate($iMonth, $iDay, $iYear)) {
return static::getIDCardVerifyNumber(substr($id, 0, 17)) != substr($id, 17, 1) ? false : true;
}
}
Expand Down Expand Up @@ -121,8 +118,7 @@ protected static function getIDCardVerifyNumber(string $idcardBase) : string

$checksum = 0;

for ( $i = 0; $i < strlen($idcardBase); $i++ )
{
for ($i = 0; $i < strlen($idcardBase); $i++) {
$checksum += substr($idcardBase, $i, 1) * $factor[$i];
}

Expand Down Expand Up @@ -24824,7 +24820,7 @@ protected function __construct()
/**
* Get region with ID card.
*
* @return array
* @return string
*/
public function getArea()
{
Expand All @@ -24836,12 +24832,11 @@ public function getArea()
*
* @return string|null
*/
public function getProvince() : ?string
public function getProvince(): ?string
{
$k = substr(static::$idCard, 0, 2) . '0000';

if ( ! isset($this->regions[$k]) )
{
if (! isset($this->regions[$k])) {
return null;
}

Expand All @@ -24853,12 +24848,11 @@ public function getProvince() : ?string
*
* @return string|null
*/
public function getCity() : ?string
public function getCity(): ?string
{
$k = substr(static::$idCard, 0, 4) . '00';

if ( ! isset($this->regions[$k]) )
{
if (! isset($this->regions[$k])) {
return null;
}

Expand All @@ -24874,8 +24868,7 @@ public function getCounty() : ?string
{
$k = substr(static::$idCard, 0, 6);

if ( ! isset($this->regions[$k]) )
{
if (! isset($this->regions[$k])) {
return null;
}

Expand All @@ -24900,7 +24893,7 @@ public function getGender() : string
/**
* Get birthday date information.
*
* @param string $format Dateformat Default example: 'Y-m-d'
* @param string $format Dateformat Default example: 'Y-m-d'
*
* @return string
*/
Expand All @@ -24923,7 +24916,7 @@ public function getBirthday(string $format = 'Y-m-d') : string
*
* @return int
*/
public function getAge() : int
public function getAge(): int
{
$today = strtotime('today');

Expand All @@ -24937,7 +24930,7 @@ public function getAge() : int
*
* @return string
*/
public function getZodiac() : string
public function getZodiac(): string
{
$locale = [
'zh-cn' => ['', '', '', '', '', '', '', '', '', '', '', ''],
Expand All @@ -24952,21 +24945,19 @@ public function getZodiac() : string
*
* @return string
*/
public function getConstellation() : string
public function getConstellation(): string
{
$month = (int) substr(static::$idCard, 10, 2);

$month = $month - 1;

$day = (int) substr(static::$idCard, 12, 2);

if ( $day < $this->constellationEdgeDays[$month] )
{
if ($day < $this->constellationEdgeDays[$month]) {
$month = $month - 1;
}

if ( $month > 0 )
{
if ($month > 0) {
return $this->constellations[static::getLocale()][$month];
}

Expand Down Expand Up @@ -25029,4 +25020,4 @@ public function __toString()
return $this->toJson();
}

}
}

0 comments on commit e1e66b7

Please sign in to comment.