Skip to content

Commit

Permalink
Merge pull request #12 from ofcold/master
Browse files Browse the repository at this point in the history
formatting
  • Loading branch information
lilianjin authored Jun 19, 2018
2 parents 3e38fa6 + fac3a0e commit 28b7eb3
Showing 1 changed file with 75 additions and 63 deletions.
138 changes: 75 additions & 63 deletions src/IdentityCard.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,49 +3,49 @@
namespace Ofcold\IdentityCard;

/**
* Class IdentityCard
* Class IdentityCard
*
* @link https://ofcold.com
* @link https://ofcold.com/license
* @link https://ofcold.com
* @link https://ofcold.com/license
*
* @author Ofcold <[email protected]>
* @author Olivia Fu <[email protected]>
* @author Bill Li <[email protected]>
* @author Ofcold <[email protected]>
* @author Olivia Fu <[email protected]>
* @author Bill Li <[email protected]>
*
* @package Ofcold\IdentityCard\IdentityCard
* @package Ofcold\IdentityCard\IdentityCard
*
* @copyright Copyright (c) 2017-2018, Ofcold. All rights reserved.
* @copyright Copyright (c) 2017-2018, Ofcold. All rights reserved.
*/
class IdentityCard
{
/**
* The IdentityCard isntance.
* The IdentityCard isntance.
*
* @var IdentityCard|null
* @var IdentityCard|null
*/
protected static $instance;

/**
* The user id card.
* The user id card.
*
* @var string
* @var string
*/
protected static $idCard;

/**
* Get the lcoale slog.
* Get the lcoale slog.
*
* @var string
* @var string
*/
protected static $locale;

/**
* Create an new IdentityCard instance.
* Create an new IdentityCard instance.
*
* @param string $idCard
* @param string $locale
* @param string $idCard
* @param string $locale
*
* @return $this
* @return $this
*/
public static function make(string $idCard, string $locale = 'zh-cn')
{
Expand All @@ -62,19 +62,19 @@ public static function make(string $idCard, string $locale = 'zh-cn')
}

/**
* Get the locale.
* Get the locale.
*
* @return string
* @return string
*/
public static function getLocale() : string
{
return static::$locale ?: 'zh-cn';
}

/**
* Verify your ID card is legal.
* Verify your ID card is legal.
*
* @return bool
* @return bool
*/
protected static function check() : bool
{
Expand All @@ -95,23 +95,23 @@ protected static function check() : bool
}

/**
* Through the regular expression preliminary detection ID number illegality.
* Through the regular expression preliminary detection ID number illegality.
*
* @param string $idCard
* @param string $idCard
*
* @return bool
* @return bool
*/
protected static function checkFirst(string $idCard) : bool
{
return preg_match('/^\d{6}(18|19|20)\d{2}(0[1-9]|1[012])(0[1-9]|[12]\d|3[01])\d{3}(\d|X)$/', $idCard);
}

/**
* According to the first 17 digits of ID card to calculate the last check digit of ID card
* According to the first 17 digits of ID card to calculate the last check digit of ID card
*
* @param string $idcardBase
* @param string $idcardBase
*
* @return string
* @return string
*/
protected static function getIDCardVerifyNumber(string $idcardBase) : string
{
Expand All @@ -123,7 +123,7 @@ protected static function getIDCardVerifyNumber(string $idcardBase) : string

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

$mod = $checksum % 11;
Expand All @@ -132,9 +132,9 @@ protected static function getIDCardVerifyNumber(string $idcardBase) : string
}

/**
* Constellations(Data from Wikipedia https://zh.wikipedia.org/wiki/%E8%A5%BF%E6%B4%8B%E5%8D%A0%E6%98%9F%E8%A1%93)
* Constellations(Data from Wikipedia https://zh.wikipedia.org/wiki/%E8%A5%BF%E6%B4%8B%E5%8D%A0%E6%98%9F%E8%A1%93)
*
* @var array
* @var array
*/
protected $constellations = [
'zh-cn' => [
Expand Down Expand Up @@ -180,16 +180,16 @@ protected static function getIDCardVerifyNumber(string $idcardBase) : string
];

/**
* Constellation edge day cut data.
* Constellation edge day cut data.
*
* @var array
* @var array
*/
protected $constellationEdgeDays = [21, 20, 21, 20, 21, 22, 23, 23, 23, 24, 22, 21];

/**
* People's Republic of China provincial administrative divisions code (excluding Hong Kong, Macao and Taiwan regions).
* People's Republic of China provincial administrative divisions code (excluding Hong Kong, Macao and Taiwan regions).
*
* var array
* @var array
*/
protected $regions = [
'110000' => [
Expand Down Expand Up @@ -24811,30 +24811,30 @@ protected static function getIDCardVerifyNumber(string $idcardBase) : string
];

/**
* Stop building an ID card instance.
* Stop building an ID card instance.
*
* @return void
* @return void
*
* @throws InvalidArgumentException
* @throws InvalidArgumentException
*/
protected function __construct()
{
}

/**
* Get region with ID card.
* Get region with ID card.
*
* @return array
* @return array
*/
public function getArea()
{
return "{$this->getProvince()} {$this->getCity()} {$this->getCounty()}";
}

/**
* Get the province.
* Get the province.
*
* @return string|null
* @return string|null
*/
public function getProvince() : ?string
{
Expand All @@ -24849,9 +24849,9 @@ public function getProvince() : ?string
}

/**
* Get the city.
* Get the city.
*
* @return string|null
* @return string|null
*/
public function getCity() : ?string
{
Expand All @@ -24866,9 +24866,9 @@ public function getCity() : ?string
}

/**
* Get the county.
* Get the county.
*
* @return string|null
* @return string|null
*/
public function getCounty() : ?string
{
Expand All @@ -24883,9 +24883,9 @@ public function getCounty() : ?string
}

/**
* Get the user gender.
* Get the user gender.
*
* @return string
* @return string
*/
public function getGender() : string
{
Expand All @@ -24898,11 +24898,11 @@ public function getGender() : string
}

/**
* Get birthday date information.
* Get birthday date information.
*
* @param string $format Dateformat Default example: 'Y-m-d'
* @param string $format Dateformat Default example: 'Y-m-d'
*
* @return string
* @return string
*/
public function getBirthday(string $format = 'Y-m-d') : string
{
Expand All @@ -24919,9 +24919,9 @@ public function getBirthday(string $format = 'Y-m-d') : string
}

/**
* Get the user age.
* Get the user age.
*
* @return int
* @return int
*/
public function getAge() : int
{
Expand All @@ -24933,9 +24933,9 @@ public function getAge() : int
}

/**
* Return user zodiac.
* Return user zodiac.
*
* @return string
* @return string
*/
public function getZodiac() : string
{
Expand All @@ -24948,9 +24948,9 @@ public function getZodiac() : string
}

/**
* Get the user constellation.
* Get the user constellation.
*
* @return string
* @return string
*/
public function getConstellation() : string
{
Expand All @@ -24974,21 +24974,21 @@ public function getConstellation() : string
}

/**
* Get the personal information of item as JSON.
* Get the personal information of item as JSON.
*
* @param int $options
* @param int $options
*
* @return string
* @return string
*/
public function toJson(int $options = 0) : string
{
return json_encode($this->toArray(), $options);
}

/**
* Get the personal information of item as a plain array.
* Get the personal information of item as a plain array.
*
* @return array
* @return array
*/
public function toArray() : array
{
Expand All @@ -25005,16 +25005,28 @@ public function toArray() : array
];
}

/**
* Get a attibutes value from the object.
*
* @param string $key
*
* @return mixed
*/
public function __get($key)
{
$result = $this->toArray();

return $result[$key] ?? $result;
}

/**
* Returns a string json of this object.
*
* @return string
*/
public function __toString()
{
return $this->toJson();
}

}
}

0 comments on commit 28b7eb3

Please sign in to comment.