Skip to content

Commit cd25668

Browse files
committed
Refactor
1 parent 4ffee55 commit cd25668

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

src/IdValidator.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function isValid($id)
2828
{
2929
// 基础验证
3030
$code = $this->_checkIdArgument($id);
31-
if (!$code) {
31+
if (empty($code)) {
3232
return false;
3333
}
3434

@@ -53,9 +53,7 @@ public function isValid($id)
5353
}
5454

5555
// 验证:校验码
56-
// 详细计算方法,点击百科:
57-
// https://zh.wikipedia.org/wiki/中华人民共和国公民身份号码
58-
$checkBit = $this->generatorCheckBit($code['body']);
56+
$checkBit = $this->_generatorCheckBit($code['body']);
5957

6058
// 检查校验码
6159
if ($checkBit != $code['checkBit']) {
@@ -79,9 +77,10 @@ public function getInfo($id)
7977
return false;
8078
}
8179
$code = $this->_checkIdArgument($id);
80+
$addressInfo = $this->_getAddressInfo($code['addressCode']);
8281
$info = [];
8382
$info['addressCode'] = $code['addressCode'];
84-
$info['address'] = implode($this->_getAddressInfo($code['addressCode']));
83+
$info['address'] = is_array($addressInfo) ? implode($addressInfo) : '';
8584
$info['birthdayCode'] = date('Y-m-d', strtotime($code['birthdayCode']));
8685
$info['sex'] = ($code['order'] % 2 === 0 ? 0 : 1);
8786
$info['length'] = $code['type'];
@@ -112,7 +111,7 @@ public function fakeId($eighteen = true)
112111

113112
$body = $addressCode.$birthdayCode.$this->_getStrPad($this->_generatorRandInt(999, 1), 3, '1');
114113

115-
$checkBit = $this->generatorCheckBit($body);
114+
$checkBit = $this->_generatorCheckBit($body);
116115

117116
return $body.$checkBit;
118117
}
@@ -295,12 +294,12 @@ private function _generatorRandInt($max, $min = 1)
295294

296295
/**
297296
* 生成校验码
298-
*
297+
* 详细计算方法 @lint https://zh.wikipedia.org/wiki/中华人民共和国公民身份号码
299298
* @param $body
300299
*
301300
* @return int|string
302301
*/
303-
private function generatorCheckBit($body)
302+
private function _generatorCheckBit($body)
304303
{
305304
// 位置加权
306305
$posWeight = $this->_getPosWeight();

0 commit comments

Comments
 (0)