Skip to content

Commit 9a3c51e

Browse files
authored
Merge pull request #11023 from Vitaliy-1/i11022_str_getcsv
#11022 Fix str_getcsv() warning php8.4
2 parents 2f0059f + 9298093 commit 9a3c51e

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

classes/dev/ComposerScript.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/**
34
* @file classes/dev/ComposerScript.php
45
*
@@ -40,24 +41,24 @@ public static function isoFileCheck(): void
4041
public static function weblateFilesDownload(): void
4142
{
4243
try {
43-
$dirPath = dirname(__FILE__, 3) . "/lib/weblateLanguages";
44-
$langFilePath = "$dirPath/languages.json";
44+
$dirPath = dirname(__FILE__, 3) . '/lib/weblateLanguages';
45+
$langFilePath = "{$dirPath}/languages.json";
4546
$urlCsv = 'https://raw.githubusercontent.com/WeblateOrg/language-data/main/languages.csv';
4647

4748
if (!is_dir($dirPath)) {
4849
mkdir($dirPath);
4950
}
5051

5152
$streamContext = stream_context_create(['http' => ['method' => 'HEAD']]);
52-
$languagesCsv = !preg_match('/200 OK/', get_headers($urlCsv, false, $streamContext)[0] ?? "") ?: file($urlCsv, FILE_SKIP_EMPTY_LINES);
53+
$languagesCsv = !preg_match('/200 OK/', get_headers($urlCsv, false, $streamContext)[0] ?? '') ?: file($urlCsv, FILE_SKIP_EMPTY_LINES);
5354
if (!is_array($languagesCsv) || !$languagesCsv) {
5455
throw new Exception(__METHOD__ . " : The Weblate file 'languages.csv' cannot be downloaded !");
5556
}
5657

5758
array_shift($languagesCsv);
5859
$languages = [];
59-
foreach($languagesCsv as $languageCsv) {
60-
$localeAndName = str_getcsv($languageCsv, ",");
60+
foreach ($languagesCsv as $languageCsv) {
61+
$localeAndName = str_getcsv($languageCsv, ',', escape: '\\');
6162
if (isset($localeAndName[0], $localeAndName[1]) && preg_match('/^[\w@-]{2,50}$/', $localeAndName[0])) {
6263
$displayName = locale_get_display_name($localeAndName[0], 'en');
6364
$languages[$localeAndName[0]] = (($displayName && $displayName !== $localeAndName[0]) ? $displayName : $localeAndName[1]);
@@ -66,7 +67,7 @@ public static function weblateFilesDownload(): void
6667

6768
$languagesJson = json_encode($languages, JSON_THROW_ON_ERROR);
6869
if (!$languagesJson || !file_put_contents($langFilePath, $languagesJson)) {
69-
throw new Exception(__METHOD__ . " : Json file empty, or save unsuccessful: $langFilePath !");
70+
throw new Exception(__METHOD__ . " : Json file empty, or save unsuccessful: {$langFilePath} !");
7071
}
7172
} catch (Exception $e) {
7273
error_log($e->getMessage());

0 commit comments

Comments
 (0)