Skip to content

Commit 5b05951

Browse files
committed
8.3
1 parent 215c2ae commit 5b05951

File tree

3 files changed

+18
-13
lines changed

3 files changed

+18
-13
lines changed

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
strategy:
1010
fail-fast: true
1111
matrix:
12-
php: [ '5.5.9', '5.6', '7.1','7.2', '7.3', '7.4', '8.0', '8.1', '8.2' ]
12+
php: [ '5.5.9', '5.6', '7.1','7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3' ]
1313
stability: [ prefer-stable ]
1414

1515
name: PHP ${{ matrix.php }} - ${{ matrix.stability }}

resources/converter.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,31 @@
44

55
use Recca0120\Twzipcode\Storages\File;
66

7+
set_error_handler(static function ($severity, $message, $file, $line) {
8+
throw new ErrorException($message, $severity, $severity, $file, $line);
9+
});
10+
711
$start = microtime(true);
812
$file = __DIR__.'/Zip32_utf8_10501_1.zip';
913

1014
// https://data.gov.tw/dataset/5948
11-
$url = 'https://quality.data.gov.tw/dq_download_csv.php?nid=5948&md5_url=b7ce2082883f6b680810828799d4c32e';
15+
$url = 'https://quality.data.gov.tw/dq_download_csv.php?nid=5948&md5_url=e1f6004ad33eb3ff3a824fb992a4b01a';
1216

1317
if (file_exists($file) === false) {
1418
touch($file);
1519
$contents = file_get_contents($url);
20+
1621
$encoding = mb_detect_encoding($contents, ['UCS-2LE', 'BIG5', 'UTF-8']);
1722
if ($encoding !== 'UTF-8') {
1823
$contents = mb_convert_encoding($contents, 'UTF-8', $encoding);
1924
}
2025
$contents = preg_replace("/^\xEF\xBB\xBF/", '', $contents);
2126
$contents = trim(str_replace('Zip5,City,Area,Road,Scope', '', $contents));
2227

28+
if (strpos('Zip5,City,Area,Road,Scope', $contents) === false) {
29+
throw new RuntimeException($contents);
30+
}
31+
2332
$zip = new ZipArchive;
2433
$zip->open($file, ZipArchive::OVERWRITE);
2534
$zip->addFromString(pathinfo($file, PATHINFO_FILENAME).'.csv', $contents);

src/Storages/File.php

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function zip3(Address $address)
4242

4343
foreach ([2, 1] as $value) {
4444
$flat = $address->flat($value);
45-
if (isset(self::$cached['zip3'][$flat])) {
45+
if (! empty(self::$cached['zip3'][$flat])) {
4646
return self::$cached['zip3'][$flat];
4747
}
4848
}
@@ -65,11 +65,11 @@ function ($zipcode, $county, $district, $rules) use (&$zip5, &$zip3) {
6565
return new Rule($rule);
6666
}, $rules));
6767

68-
if (isset($zip3[$county]) === false) {
68+
if (empty($zip3[$county])) {
6969
$zip3[$county] = substr($zipcode, 0, 1);
7070
}
7171

72-
if (isset($zip3[$county.$district]) === false) {
72+
if (empty($zip3[$county.$district])) {
7373
$zip3[$county.$district] = substr($zipcode, 0, 3);
7474
}
7575
});
@@ -88,7 +88,7 @@ public function rules($zip3)
8888
{
8989
$this->restore('zip5');
9090

91-
return isset(self::$cached['zip5'][$zip3]) === true
91+
return ! empty(self::$cached['zip5'][$zip3])
9292
? new JArray($this->decompress(self::$cached['zip5'][$zip3]))
9393
: new JArray([]);
9494
}
@@ -160,17 +160,13 @@ private function getSource($file)
160160
*/
161161
private function prepareSource($source)
162162
{
163-
$tricks = [
164-
'宜蘭縣壯圍鄉' => '263',
165-
'新竹縣寶山鄉' => '308',
166-
'臺南市新市區' => '744',
167-
];
163+
$tricks = ['宜蘭縣壯圍鄉' => '263', '新竹縣寶山鄉' => '308', '臺南市新市區' => '744'];
168164
$results = [];
169165
$rules = preg_split('/\n|\r\n$/', $source);
170166
foreach ($rules as $rule) {
171-
if (empty(trim($rule)) === false) {
167+
if (! empty(trim($rule))) {
172168
list($zipcode, $county, $district) = explode(',', $rule);
173-
$zip3 = isset($tricks[$county.$district]) === true
169+
$zip3 = ! empty($tricks[$county.$district])
174170
? $tricks[$county.$district]
175171
: substr($zipcode, 0, 3);
176172
$results[$county][$district][$zip3][] = $rule;

0 commit comments

Comments
 (0)