Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove empty strings #488

Merged
merged 1 commit into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 8 additions & 20 deletions countries.json
Original file line number Diff line number Diff line change
Expand Up @@ -1720,9 +1720,7 @@
"root": "",
"suffixes": []
},
"capital": [
""
],
"capital": [],
"altSpellings": [
"AQ"
],
Expand Down Expand Up @@ -5791,9 +5789,7 @@
"7"
]
},
"capital": [
""
],
"capital": [],
"altSpellings": [
"BV",
"Bouvet\u00f8ya",
Expand Down Expand Up @@ -15346,13 +15342,9 @@
"currencies": {},
"idd": {
"root": "",
"suffixes": [
""
]
"suffixes": []
},
"capital": [
""
],
"capital": [],
"altSpellings": [
"HM",
"Heard Island and McDonald Islands"
Expand Down Expand Up @@ -15380,7 +15372,7 @@
"common": "Heard ja McDonaldinsaaret"
},
"fra": {
"official": "Des \u00eeles Heard et McDonald",
"official": "\u00celes Heard-et-MacDonald",
"common": "\u00celes Heard-et-MacDonald"
},
"hrv": {
Expand Down Expand Up @@ -21371,9 +21363,7 @@
"53"
]
},
"capital": [
""
],
"capital": [],
"altSpellings": [
"MO",
"\u6fb3\u95e8",
Expand Down Expand Up @@ -30139,7 +30129,7 @@
"currencies": {
"SDG": {
"name": "Sudanese pound",
"symbol": ""
"symbol": "PT"
}
},
"idd": {
Expand Down Expand Up @@ -36135,9 +36125,7 @@
"68"
]
},
"capital": [
""
],
"capital": [],
"altSpellings": [
"UM"
],
Expand Down
12 changes: 6 additions & 6 deletions dist/countries-unescaped.json

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions dist/countries.csv

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions dist/countries.json

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions dist/countries.xml

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions dist/countries.yml

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions src/MLD/Console/Command/ExportCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
class ExportCommand extends Command
{
private const BASE_OUTPUT_FILENAME = 'countries';
private const EXIT_FAILURE = 1;
private const EXIT_SUCCESS = 0;

private string $inputFile;

Expand Down Expand Up @@ -97,18 +99,17 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$countries = $this->decodeInputFile();
} catch (JsonException $exception) {
$output->writeln(sprintf('Failed to decode input countries file: %s', $exception->getMessage()));
return 1;
return self::EXIT_FAILURE;
}

$countries = $this->generateFields($countries);
$countries = $this->generateCallingCodes($countries);

$outputFields = $this->getOutputFields($input, $countries);
if ($output->isVerbose()) {
$output->writeln(sprintf('Output fields: %s', implode(',', $outputFields)));
}

$countries = $this->filterFields($countries, $outputFields);

$formats = $this->getFormats($input);
foreach ($formats as $format) {
if ($output->isVerbose()) {
Expand All @@ -129,7 +130,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
}

$this->printResult($output, $countries, $formats);
return 0;
return self::EXIT_SUCCESS;
}

/**
Expand Down Expand Up @@ -273,11 +274,10 @@ private function setOutputDirectory(InputInterface $input): void
}

/**
* Generate fields that exist only at build time
* Generate calling codes from the "idd" property
*/
private function generateFields(array $countries): array
private function generateCallingCodes(array $countries): array
{
// generate calling codes from the "idd" property
$generateCallingCodes = static function ($country) {
$country[Fields::CALLING_CODES->value] = array_map(
static fn($suffix): string => $country[Fields::IDD->value][Fields::IDD_ROOT->value] . $suffix,
Expand Down