]> BookStack Code Mirror - bookstack/commitdiff
Addressed setlocale issue caught by phpstan
authorDan Brown <redacted>
Mon, 5 Sep 2022 12:33:05 +0000 (13:33 +0100)
committerDan Brown <redacted>
Mon, 5 Sep 2022 12:33:05 +0000 (13:33 +0100)
setlocale could be called with no second param if the language given to
the modified function was empty.

app/Util/LanguageManager.php

index c33c73ad5ce64123d594be6aff9084a404170a89..33ec0e3a96d4adb1186d4ead08780ef4aafb2e4d 100644 (file)
@@ -113,7 +113,7 @@ class LanguageManager
      * Set the system date locale for localized date formatting.
      * Will try both the standard locale name and the UTF8 variant.
      */
      * Set the system date locale for localized date formatting.
      * Will try both the standard locale name and the UTF8 variant.
      */
-    public function setPhpDateTimeLocale(string $language)
+    public function setPhpDateTimeLocale(string $language): void
     {
         $isoLang = $this->localeMap[$language]['iso'] ?? false;
 
     {
         $isoLang = $this->localeMap[$language]['iso'] ?? false;
 
@@ -125,6 +125,8 @@ class LanguageManager
             $language,
         ]);
 
             $language,
         ]);
 
-        setlocale(LC_TIME, ...$locales);
+        if (!empty($locales)) {
+            setlocale(LC_TIME, ...$locales);
+        }
     }
 }
     }
 }