Skip to content

Commit

Permalink
Support PHP5.6
Browse files Browse the repository at this point in the history
  • Loading branch information
yangliulnn committed Aug 7, 2017
1 parent e442f28 commit d652854
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .scrutinizer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ filter:
build:
environment:
php:
version: 7.0.7
version: 5.6.31
tests:
override:
-
Expand Down
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ language: php

php:
# aliased to a recent 7.0.x version
- 5.6
- 7.0

before_script:
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
}
],
"require": {
"php": ">=7.0"
"php": ">=5.6"
},
"autoload": {
"psr-4": {
Expand Down
34 changes: 17 additions & 17 deletions src/IDCard.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class IDCard
*/
protected $areaCodes;

public function __construct(string $id)
public function __construct($id)
{
$this->id = strtoupper($id);
$this->areaCodes = (array) require __DIR__.'/../data/codes.php';
Expand All @@ -29,7 +29,7 @@ public function __construct(string $id)
*
* @return bool
*/
public function check() : bool
public function check()
{
return $this->checkAreaCode() && $this->checkBirthday() && $this->checkCode();
}
Expand All @@ -39,7 +39,7 @@ public function check() : bool
*
* @return bool
*/
public function checkAreaCode() : bool
public function checkAreaCode()
{
$areaCode = substr($this->id, 0, 6);

Expand All @@ -51,7 +51,7 @@ public function checkAreaCode() : bool
*
* @return bool
*/
public function checkBirthday() : bool
public function checkBirthday()
{
$year = substr($this->id, 6, 4);
$month = substr($this->id, 10, 2);
Expand All @@ -65,7 +65,7 @@ public function checkBirthday() : bool
*
* @return bool
*/
public function checkCode() : bool
public function checkCode()
{
$weight = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2];
$codes = ['1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2'];
Expand All @@ -85,7 +85,7 @@ public function checkCode() : bool
*
* @return string
*/
public function address(string $separator = '') : string
public function address($separator = '')
{
return $this->province().$separator.$this->city().$separator.$this->zone();
}
Expand All @@ -95,7 +95,7 @@ public function address(string $separator = '') : string
*
* @return string
*/
public function province() : string
public function province()
{
return $this->areaCodes[substr($this->id, 0, 2).'0000'];
}
Expand All @@ -105,7 +105,7 @@ public function province() : string
*
* @return string
*/
public function city() : string
public function city()
{
return $this->areaCodes[substr($this->id, 0, 4).'00'];
}
Expand All @@ -115,7 +115,7 @@ public function city() : string
*
* @return string
*/
public function zone() : string
public function zone()
{
return $this->areaCodes[substr($this->id, 0, 6)];
}
Expand All @@ -127,7 +127,7 @@ public function zone() : string
*
* @return string
*/
public function birthday(string $format) : string
public function birthday($format = 'Y-m-d')
{
return date($format, strtotime($this->year().'-'.$this->month().'-'.$this->day()));
}
Expand All @@ -137,7 +137,7 @@ public function birthday(string $format) : string
*
* @return int
*/
public function year() : int
public function year()
{
return (int) substr($this->id, 6, 4);
}
Expand All @@ -147,7 +147,7 @@ public function year() : int
*
* @return int
*/
public function month() : int
public function month()
{
return (int) substr($this->id, 10, 2);
}
Expand All @@ -157,7 +157,7 @@ public function month() : int
*
* @return int
*/
public function day() : int
public function day()
{
return (int) substr($this->id, 12, 2);
}
Expand All @@ -167,7 +167,7 @@ public function day() : int
*
* @return int
*/
public function age() : int
public function age()
{
$year = $this->year();
$month = $this->month();
Expand All @@ -190,7 +190,7 @@ public function age() : int
*
* @return string
*/
public function sex() : string
public function sex()
{
return substr($this->id, 16, 1) % 2 ? '' : '';
}
Expand All @@ -200,7 +200,7 @@ public function sex() : string
*
* @return string
*/
public function constellation() : string
public function constellation()
{
$constellation = ['水瓶座', '双鱼座', '白羊座', '金牛座', '双子座', '巨蟹座', '狮子座', '处女座', '天秤座', '天蝎座', '射手座', '魔羯座'];
$constellationDays = [21, 20, 21, 20, 21, 22, 23, 23, 23, 24, 22, 21];
Expand All @@ -220,7 +220,7 @@ public function constellation() : string
*
* @return string
*/
public function zodiac() : string
public function zodiac()
{
$zodiac = ['', '', '', '', '', '', '', '', '', '', '', ''];
$index = abs($this->year() - 1901) % 12;
Expand Down

0 comments on commit d652854

Please sign in to comment.