diff --git a/composer.lock b/composer.lock index 0db5660b..6ccfea61 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "af4e82e5f2897d2cd7b5ef89e2393004", + "content-hash": "53fc53b1dd925583e5a4cb916927bd52", "packages": [ { "name": "psr/container", @@ -794,12 +794,12 @@ "source": { "type": "git", "url": "https://github.com/Roave/SecurityAdvisories.git", - "reference": "244ae4d2e7c97fd65c23c34990f4e98571fd4729" + "reference": "6cbe3472c940a80f587886423020673520d36a29" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Roave/SecurityAdvisories/zipball/244ae4d2e7c97fd65c23c34990f4e98571fd4729", - "reference": "244ae4d2e7c97fd65c23c34990f4e98571fd4729", + "url": "https://api.github.com/repos/Roave/SecurityAdvisories/zipball/6cbe3472c940a80f587886423020673520d36a29", + "reference": "6cbe3472c940a80f587886423020673520d36a29", "shasum": "" }, "conflict": { @@ -1123,7 +1123,7 @@ "open-web-analytics/open-web-analytics": "<1.7.4", "opencart/opencart": "<=3.0.3.7", "openid/php-openid": "<2.3", - "openmage/magento-lts": "<19.4.22|>=20,<20.0.19", + "openmage/magento-lts": "<=19.5|>=20,<=20.1", "opensource-workshop/connect-cms": "<1.7.2|>=2,<2.3.2", "orchid/platform": ">=9,<9.4.4|>=14.0.0.0-alpha4,<14.5", "oro/commerce": ">=4.1,<5.0.6", @@ -1452,7 +1452,7 @@ "type": "tidelift" } ], - "time": "2023-09-11T14:04:42+00:00" + "time": "2023-09-11T21:04:03+00:00" } ], "aliases": [], @@ -1463,6 +1463,7 @@ "prefer-stable": false, "prefer-lowest": false, "platform": { + "ext-dom": "*", "ext-gettext": "*", "php": ">=8.1" }, diff --git a/src/MLD/Console/Command/ExportCommand.php b/src/MLD/Console/Command/ExportCommand.php index fbaa75b1..86fdaac1 100755 --- a/src/MLD/Console/Command/ExportCommand.php +++ b/src/MLD/Console/Command/ExportCommand.php @@ -4,6 +4,7 @@ namespace MLD\Console\Command; +use JsonException; use MLD\Converter\Factory; use MLD\Enum\ExportCommandOptions; use MLD\Enum\Formats; @@ -90,7 +91,12 @@ protected function execute(InputInterface $input, OutputInterface $output): int $this->setOutputDirectory($input); $this->createOutputDirectory($output); - $countries = $this->decodeInputFile(); + try { + $countries = $this->decodeInputFile(); + } catch (JsonException $exception) { + $output->writeln(sprintf('Failed to decode input countries file: %s', $exception->getMessage())); + return 1; + } $outputFields = $this->getOutputFields($input, $countries); if ($output->isVerbose()) { @@ -194,10 +200,11 @@ private function getOutputFields(InputInterface $input, array $countries): array /** * @return array + * @throws JsonException */ private function decodeInputFile(): array { - return json_decode(file_get_contents($this->inputFile), true); + return json_decode(file_get_contents($this->inputFile), true, 512, JSON_THROW_ON_ERROR); } /** diff --git a/src/MLD/Converter/AbstractJsonConverter.php b/src/MLD/Converter/AbstractJsonConverter.php index 22653abe..b29f3cd2 100755 --- a/src/MLD/Converter/AbstractJsonConverter.php +++ b/src/MLD/Converter/AbstractJsonConverter.php @@ -37,7 +37,7 @@ abstract protected function jsonEncode(array $countries): string; protected function processEmptyArrays(array $countries): array { return array_map( - function ($country) { + static function ($country) { if (isset($country[Fields::LANGUAGES]) && empty($country[Fields::LANGUAGES])) { $country[Fields::LANGUAGES] = new stdClass(); } diff --git a/src/MLD/Converter/JsonConverter.php b/src/MLD/Converter/JsonConverter.php index 88eabb3f..21fd7250 100755 --- a/src/MLD/Converter/JsonConverter.php +++ b/src/MLD/Converter/JsonConverter.php @@ -4,6 +4,8 @@ namespace MLD\Converter; +use JsonException; + /** * Convert countries data to JSON format */ @@ -11,9 +13,10 @@ class JsonConverter extends AbstractJsonConverter { /** * @inheritDoc + * @throws JsonException */ protected function jsonEncode(array $countries): string { - return json_encode($countries); + return json_encode($countries, JSON_THROW_ON_ERROR); } } \ No newline at end of file diff --git a/src/MLD/Converter/JsonConverterUnicode.php b/src/MLD/Converter/JsonConverterUnicode.php index 7b056866..c85921f6 100755 --- a/src/MLD/Converter/JsonConverterUnicode.php +++ b/src/MLD/Converter/JsonConverterUnicode.php @@ -4,6 +4,8 @@ namespace MLD\Converter; +use JsonException; + /** * Convert countries data to JSON format with unescaped characters */ @@ -11,9 +13,10 @@ class JsonConverterUnicode extends AbstractJsonConverter { /** * @inheritdoc + * @throws JsonException */ protected function jsonEncode(array $countries): string { - return json_encode($countries, JSON_UNESCAPED_UNICODE); + return json_encode($countries, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE); } } \ No newline at end of file diff --git a/src/MLD/Converter/XmlConverter.php b/src/MLD/Converter/XmlConverter.php index 0c5fdffd..f4d69297 100755 --- a/src/MLD/Converter/XmlConverter.php +++ b/src/MLD/Converter/XmlConverter.php @@ -51,7 +51,7 @@ private function processCountry(array $country): void { $countryNode = $this->domDocument->createElement('country'); $country = $this->flatten($country); - array_walk($country, function ($value, $key) use ($countryNode) { + array_walk($country, static function ($value, $key) use ($countryNode) { $countryNode->setAttribute($key, (string) $value); }); $this->domDocument->documentElement->appendChild($countryNode); diff --git a/src/MLD/Converter/YamlConverter.php b/src/MLD/Converter/YamlConverter.php index 5d66dde5..9c184fda 100755 --- a/src/MLD/Converter/YamlConverter.php +++ b/src/MLD/Converter/YamlConverter.php @@ -18,8 +18,6 @@ class YamlConverter extends AbstractConverter */ public function convert(array $countries): string { - $dumper = new Dumper(); - - return $dumper->dump($countries, self::INLINE_LEVEL); + return (new Dumper())->dump($countries, self::INLINE_LEVEL); } } \ No newline at end of file