Skip to content

Commit 248d58f

Browse files
committed
Apply fixes from StyleCI
1 parent c5e18f4 commit 248d58f

2 files changed

Lines changed: 50 additions & 52 deletions

File tree

src/IdValidator.php

Lines changed: 38 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -192,33 +192,31 @@ private function _getAddressInfo($addressCode)
192192

193193
public function _getConstellation($birthdayCode)
194194
{
195-
196195
$constellationList = $this->_getConstellationList();
197196

198-
$time = strtotime($birthdayCode);
199-
$year = substr($birthdayCode, 0,4);
197+
$time = strtotime($birthdayCode);
198+
$year = substr($birthdayCode, 0, 4);
200199
$month = substr($birthdayCode, 4, 2);
201-
$day = substr($birthdayCode, 6,2);
202-
200+
$day = substr($birthdayCode, 6, 2);
203201

204202
// 1月份与12月份特殊处理
205-
if( ( $month == 1 && $day < 20 ) || ( $month == 12 && $day > 21 ) ){
203+
if (($month == 1 && $day < 20) || ($month == 12 && $day > 21)) {
206204
return $constellationList[12]['name'];
207-
}else if( $month == 1 ){
205+
} elseif ($month == 1) {
208206
return $constellationList[1]['name'];
209-
}else if( $month == 12 ){
207+
} elseif ($month == 12) {
210208
return $constellationList[12]['name'];
211209
}
212210

213211
$startDate = $year.'-'.$constellationList[$month]['start_date'];
214-
$endDate = $year.'-'.$constellationList[$month]['end_date'];
215-
if( strtotime( $startDate ) <= $time && strtotime( $endDate ) >= $time ){
212+
$endDate = $year.'-'.$constellationList[$month]['end_date'];
213+
if (strtotime($startDate) <= $time && strtotime($endDate) >= $time) {
216214
return $constellationList[$month]['name'];
217215
}
218-
$startDate = $year.'-'.$constellationList[$month-1]['start_date'];
219-
$endDate = $year.'-'.$constellationList[$month-1]['end_date'];
220-
if( strtotime( $startDate ) <= $time && strtotime( $endDate ) >= $time ){
221-
return $constellationList[$month-1]['name'];
216+
$startDate = $year.'-'.$constellationList[$month - 1]['start_date'];
217+
$endDate = $year.'-'.$constellationList[$month - 1]['end_date'];
218+
if (strtotime($startDate) <= $time && strtotime($endDate) >= $time) {
219+
return $constellationList[$month - 1]['name'];
222220
}
223221

224222
return '';
@@ -231,10 +229,10 @@ public function _getChineseZodiac($birthdayCode)
231229
$end = substr($birthdayCode, 0, 4);
232230
$key = ($end - $start) % 12;
233231
$key = $key >= 0 ? $key : ($key + 12);
232+
234233
return $chineseZodiacList[$key];
235234
}
236235

237-
238236
/**
239237
* 检查并拆分身份证号.
240238
*
@@ -424,57 +422,57 @@ private function _getConstellationList()
424422
{
425423
return [
426424
'01' => [
427-
'name' => '水瓶座',
425+
'name' => '水瓶座',
428426
'start_date' => '01-20',
429-
'end_date' => '02-18'
427+
'end_date' => '02-18',
430428
],
431429
'02' => [
432-
'name' => '双鱼座',
430+
'name' => '双鱼座',
433431
'start_date' => '02-19',
434-
'end_date' => '03-20'
432+
'end_date' => '03-20',
435433
],
436434
'03' => [
437-
'name' => '白羊座',
435+
'name' => '白羊座',
438436
'start_date' => '03-21',
439-
'end_date' => '04-19'
437+
'end_date' => '04-19',
440438
],
441439
'04' => [
442-
'name' => '金牛座',
440+
'name' => '金牛座',
443441
'start_date' => '04-20',
444-
'end_date' => '05-20'
442+
'end_date' => '05-20',
445443
], '05' => [
446-
'name' => '双子座',
444+
'name' => '双子座',
447445
'start_date' => '05-21',
448-
'end_date' => '06-21'
446+
'end_date' => '06-21',
449447
], '06' => [
450-
'name' => '巨蟹座',
448+
'name' => '巨蟹座',
451449
'start_date' => '06-22',
452-
'end_date' => '07-22'
450+
'end_date' => '07-22',
453451
], '07' => [
454-
'name' => '狮子座',
452+
'name' => '狮子座',
455453
'start_date' => '07-23',
456-
'end_date' => '08-22'
454+
'end_date' => '08-22',
457455
], '08' => [
458-
'name' => '处女座',
456+
'name' => '处女座',
459457
'start_date' => '08-23',
460-
'end_date' => '09-22'
458+
'end_date' => '09-22',
461459
], '09' => [
462-
'name' => '天秤座',
460+
'name' => '天秤座',
463461
'start_date' => '09-23',
464-
'end_date' => '10-23'
462+
'end_date' => '10-23',
465463
], '10' => [
466-
'name' => '天蝎座',
464+
'name' => '天蝎座',
467465
'start_date' => '10-24',
468-
'end_date' => '11-22'
466+
'end_date' => '11-22',
469467
], '11' => [
470-
'name' => '射手座',
468+
'name' => '射手座',
471469
'start_date' => '11-23',
472-
'end_date' => '12-21'
470+
'end_date' => '12-21',
473471
], '12' => [
474-
'name' => '水瓶座',
472+
'name' => '水瓶座',
475473
'start_date' => '12-22',
476-
'end_date' => '01-19'
477-
]
474+
'end_date' => '01-19',
475+
],
478476
];
479477
}
480478
}

tests/IdValidatorTest.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,27 +30,27 @@ public function testGetInfo()
3030
{
3131
$idValidator = new IdValidator();
3232
$this->assertEquals([
33-
'addressCode' => '440308',
34-
'address' => '广东省深圳市盐田区',
35-
'birthdayCode' => '1999-01-10',
33+
'addressCode' => '440308',
34+
'address' => '广东省深圳市盐田区',
35+
'birthdayCode' => '1999-01-10',
3636
'constellation' => '水瓶座',
3737
'chineseZodiac' => '卯兔',
38-
'sex' => 1,
39-
'length' => 18,
40-
'checkBit' => '2', ],
38+
'sex' => 1,
39+
'length' => 18,
40+
'checkBit' => '2', ],
4141
$idValidator->getInfo('440308199901101512'));
4242
$this->assertEquals(false, $idValidator->isValid('440308199901101513'));
4343

4444
$idValidator = new IdValidator();
4545
$this->assertEquals([
46-
'addressCode' => '610104',
47-
'address' => '陕西省西安市莲湖区',
48-
'birthdayCode' => '1962-09-27',
46+
'addressCode' => '610104',
47+
'address' => '陕西省西安市莲湖区',
48+
'birthdayCode' => '1962-09-27',
4949
'constellation' => '天秤座',
5050
'chineseZodiac' => '寅虎',
51-
'sex' => 0,
52-
'length' => 15,
53-
'checkBit' => '', ],
51+
'sex' => 0,
52+
'length' => 15,
53+
'checkBit' => '', ],
5454
$idValidator->getInfo('610104620927690'));
5555
$this->assertEquals(false, $idValidator->isValid('610104620932690'));
5656
}

0 commit comments

Comments
 (0)