Skip to content

Commit 4ffee55

Browse files
committed
Apply fixes from StyleCI
1 parent c07c806 commit 4ffee55

File tree

2 files changed

+32
-36
lines changed

2 files changed

+32
-36
lines changed

src/IdValidator.php

Lines changed: 26 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
namespace Jxlwqq\IdValidator;
44

55
/**
6-
* Class IdValidator
7-
* @package Jxlwqq\IdValidator
6+
* Class IdValidator.
87
*/
98
class IdValidator
109
{
@@ -15,7 +14,7 @@ class IdValidator
1514
*/
1615
public function __construct()
1716
{
18-
$this->_addressCodeList = include __DIR__ . '/../data/addressCode.php';
17+
$this->_addressCodeList = include __DIR__.'/../data/addressCode.php';
1918
}
2019

2120
/**
@@ -107,15 +106,15 @@ public function fakeId($eighteen = true)
107106
$birthdayCode = $this->_generatorBirthdayCode();
108107

109108
if (!$eighteen) {
110-
return $addressCode . substr($birthdayCode, 2)
111-
. $this->_getStrPad($this->_generatorRandInt(999, 1), 3, '1');
109+
return $addressCode.substr($birthdayCode, 2)
110+
.$this->_getStrPad($this->_generatorRandInt(999, 1), 3, '1');
112111
}
113112

114-
$body = $addressCode . $birthdayCode . $this->_getStrPad($this->_generatorRandInt(999, 1), 3, '1');
113+
$body = $addressCode.$birthdayCode.$this->_getStrPad($this->_generatorRandInt(999, 1), 3, '1');
115114

116115
$checkBit = $this->generatorCheckBit($body);
117116

118-
return $body . $checkBit;
117+
return $body.$checkBit;
119118
}
120119

121120
/**
@@ -138,9 +137,9 @@ private function _getPosWeight()
138137
* 获取数字补位.
139138
*
140139
* @param $str
141-
* @param int $len
140+
* @param int $len
142141
* @param string $chr
143-
* @param bool $right
142+
* @param bool $right
144143
*
145144
* @return string
146145
*/
@@ -152,9 +151,9 @@ private function _getStrPad($str, $len = 2, $chr = '0', $right = false)
152151
} else {
153152
for ($i = 0, $j = $len - strlen($str); $i < $j; $i++) {
154153
if ($right) {
155-
$str = $str . $chr;
154+
$str = $str.$chr;
156155
} else {
157-
$str = $chr . $str;
156+
$str = $chr.$str;
158157
}
159158
}
160159

@@ -173,11 +172,11 @@ private function _getAddressInfo($addressCode)
173172
{
174173
$addressInfo = [];
175174
// 省级信息
176-
$provinceAddressCode = substr($addressCode, 0, 2) . '0000';
175+
$provinceAddressCode = substr($addressCode, 0, 2).'0000';
177176
$addressInfo['province'] = isset($this->_addressCodeList[$provinceAddressCode]) ? $this->_addressCodeList[$provinceAddressCode] : '';
178177

179178
// 市级信息
180-
$cityAddressCode = substr($addressCode, 0, 4) . '00';
179+
$cityAddressCode = substr($addressCode, 0, 4).'00';
181180
$addressInfo['city'] = isset($this->_addressCodeList[$cityAddressCode]) ? $this->_addressCodeList[$cityAddressCode] : '';
182181

183182
// 县级信息
@@ -205,22 +204,22 @@ private function _checkIdArgument($id)
205204
switch ($length) {
206205
case 18:
207206
$code = [
208-
'body' => substr($id, 0, 17),
209-
'addressCode' => substr($id, 0, 6),
207+
'body' => substr($id, 0, 17),
208+
'addressCode' => substr($id, 0, 6),
210209
'birthdayCode' => substr($id, 6, 8),
211-
'order' => substr($id, 14, 3),
212-
'checkBit' => substr($id, -1),
213-
'type' => 18,
210+
'order' => substr($id, 14, 3),
211+
'checkBit' => substr($id, -1),
212+
'type' => 18,
214213
];
215214
break;
216215
case 15:
217216
$code = [
218-
'body' => $id,
219-
'addressCode' => substr($id, 0, 6),
220-
'birthdayCode' => '19' . substr($id, 6, 6),
221-
'order' => substr($id, 12, 3),
222-
'checkBit' => '',
223-
'type' => 15,
217+
'body' => $id,
218+
'addressCode' => substr($id, 0, 6),
219+
'birthdayCode' => '19'.substr($id, 6, 6),
220+
'order' => substr($id, 12, 3),
221+
'checkBit' => '',
222+
'type' => 15,
224223
];
225224
break;
226225
}
@@ -279,8 +278,6 @@ private function _checkOrderCode($orderCode)
279278
} else {
280279
return false;
281280
}
282-
283-
284281
}
285282

286283
/**
@@ -339,7 +336,7 @@ private function _generatorAddressCode()
339336
$province = $this->_getStrPad($this->_generatorRandInt(66), 2, '0');
340337
$city = $this->_getStrPad($this->_generatorRandInt(20), 2, '0');
341338
$district = $this->_getStrPad($this->_generatorRandInt(20), 2, '0');
342-
$fakeAddressCode = $province . $city . $district;
339+
$fakeAddressCode = $province.$city.$district;
343340
if (isset($this->_addressCodeList[$fakeAddressCode])) {
344341
$addressCode = $fakeAddressCode;
345342
break;
@@ -359,8 +356,8 @@ private function _generatorBirthdayCode()
359356
$year = $this->_getStrPad($this->_generatorRandInt(99, 50), 2, '0');
360357
$month = $this->_getStrPad($this->_generatorRandInt(12, 1), 2, '0');
361358
$day = $this->_getStrPad($this->_generatorRandInt(28, 1), 2, '0');
362-
$year = '19' . $year;
363-
$birthdayCode = $year . $month . $day;
359+
$year = '19'.$year;
360+
$birthdayCode = $year.$month.$day;
364361

365362
return $birthdayCode;
366363
}

tests/IdValidatorTest.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,19 @@ public function testGetInfo()
3535
'birthdayCode' => '1999-01-10',
3636
'sex' => 1,
3737
'length' => 18,
38-
'checkBit' => '2'],
38+
'checkBit' => '2', ],
3939
$idValidator->getInfo('440308199901101512'));
4040
$this->assertEquals(false, $idValidator->isValid('440308199901101513'));
4141

4242
$idValidator = new IdValidator();
4343
$this->assertEquals([
44-
'addressCode' => '610104',
45-
'address' => '陕西省西安市莲湖区',
44+
'addressCode' => '610104',
45+
'address' => '陕西省西安市莲湖区',
4646
'birthdayCode' => '1962-09-27',
47-
'sex' => 0,
48-
'length' => 15,
49-
'checkBit' => ''],
47+
'sex' => 0,
48+
'length' => 15,
49+
'checkBit' => '', ],
5050
$idValidator->getInfo('610104620927690'));
5151
$this->assertEquals(false, $idValidator->isValid('610104620932690'));
52-
5352
}
5453
}

0 commit comments

Comments
 (0)