From 907592c7b5563e1abffc8a2c6ca9eb1d2d01f2fc Mon Sep 17 00:00:00 2001
From: Tim van Dijen <tvdijen@gmail.com>
Date: Sun, 3 Feb 2019 01:23:15 +0100
Subject: [PATCH] Fixes for lib/SimpleSAML/Locale

---
 lib/SimpleSAML/Locale/Language.php     | 11 +++++++----
 lib/SimpleSAML/Locale/Localization.php |  7 ++++++-
 lib/SimpleSAML/Locale/Translate.php    |  8 ++++++--
 3 files changed, 19 insertions(+), 7 deletions(-)

diff --git a/lib/SimpleSAML/Locale/Language.php b/lib/SimpleSAML/Locale/Language.php
index 94a1c0bf4..e8f06cf09 100644
--- a/lib/SimpleSAML/Locale/Language.php
+++ b/lib/SimpleSAML/Locale/Language.php
@@ -196,6 +196,7 @@ class Language
      *
      * @param string  $language Language code for the language to set.
      * @param boolean $setLanguageCookie Whether to set the language cookie or not. Defaults to true.
+     * @return void
      */
     public function setLanguage($language, $setLanguageCookie = true)
     {
@@ -255,7 +256,7 @@ class Language
      *
      * @param string $code The ISO 639-2 code of the language.
      *
-     * @return string The localized name of the language.
+     * @return string|null The localized name of the language.
      */
     public function getLanguageLocalizedName($code)
     {
@@ -281,8 +282,8 @@ class Language
     /**
      * This method returns the preferred language for the user based on the Accept-Language HTTP header.
      *
-     * @return string The preferred language based on the Accept-Language HTTP header, or null if none of the languages
-     * in the header is available.
+     * @return string|null The preferred language based on the Accept-Language HTTP header,
+     * or null if none of the languages in the header is available.
      */
     private function getHTTPLanguage()
     {
@@ -334,7 +335,8 @@ class Language
     /**
      * Return an alias for a language code, if any.
      *
-     * @return string The alias, or null if the alias was not found.
+     * @param string $langcode
+     * @return string|null The alias, or null if the alias was not found.
      */
     public function getLanguageCodeAlias($langcode)
     {
@@ -399,6 +401,7 @@ class Language
      * specified is not in the list of available languages, or the headers have already been sent to the browser.
      *
      * @param string $language The language set by the user.
+     * @return void
      */
     public static function setLanguageCookie($language)
     {
diff --git a/lib/SimpleSAML/Locale/Localization.php b/lib/SimpleSAML/Locale/Localization.php
index 822a71f96..c9c7e93a2 100644
--- a/lib/SimpleSAML/Locale/Localization.php
+++ b/lib/SimpleSAML/Locale/Localization.php
@@ -132,6 +132,7 @@ class Localization
      *
      * @param string $module Module name
      * @param string $localeDir Absolute path if the module is housed elsewhere
+     * @return void
      */
     public function addModuleDomain($module, $localeDir = null)
     {
@@ -148,6 +149,7 @@ class Localization
      *
      * @param string $localeDir Location of translations
      * @param string $domain Domain at location
+     * @return void
      */
     public function addDomain($localeDir, $domain)
     {
@@ -156,7 +158,7 @@ class Localization
         $this->loadGettextGettextFromPO($domain);
     }
 
-    /*
+    /**
      * Get and check path of localization file
      *
      * @param string $domain Name of localization domain
@@ -205,6 +207,7 @@ class Localization
 
     /**
      * Setup the translator
+     * @return void
      */
     private function setupTranslator()
     {
@@ -221,6 +224,7 @@ class Localization
      *
      * @param string $domain Name of domain
      * @param boolean $catchException Whether to catch an exception on error or return early
+     * @return void
      *
      * @throws \Exception If something is wrong with the locale file for the domain and activated language
      */
@@ -268,6 +272,7 @@ class Localization
 
     /**
      * Set up L18N if configured or fallback to old system
+     * @return void
      */
     private function setupL10N()
     {
diff --git a/lib/SimpleSAML/Locale/Translate.php b/lib/SimpleSAML/Locale/Translate.php
index d64f222cd..a5c0442ad 100644
--- a/lib/SimpleSAML/Locale/Translate.php
+++ b/lib/SimpleSAML/Locale/Translate.php
@@ -119,7 +119,7 @@ class Translate
      * @param string $tag The tag name. The tag name can also be on the form '{<dictionary>:<tag>}', to retrieve a tag
      * from the specific dictionary.
      *
-     * @return array An associative array with language => string mappings, or null if the tag wasn't found.
+     * @return array|null An associative array with language => string mappings, or null if the tag wasn't found.
      */
     public function getTag($tag)
     {
@@ -252,6 +252,8 @@ class Translate
      * @param array        $replacements An associative array of keys that should be replaced with values in the
      *     translated string.
      * @param boolean      $fallbackdefault Default translation to use as a fallback if no valid translation was found.
+     * @param array $oldreplacements
+     * @param bool $striptags
      * @deprecated Not used in twig, gettext
      *
      * @return string  The translated tag, or a placeholder value if the tag wasn't found.
@@ -285,7 +287,7 @@ class Translate
             );
 
             // for backwards compatibility
-            if (!$replacements && $this->getTag($tag) === null) {
+            if (!$replacements && ($this->getTag($tag) === null)) {
                 \SimpleSAML\Logger::warning(
                     'Code which uses $fallbackdefault === FALSE should be updated to use the getTag() method instead.'
                 );
@@ -349,6 +351,7 @@ class Translate
      * @param array|string $translation The translation array
      *
      * @throws \Exception If $translation is neither a string nor an array.
+     * @return void
      */
     public function includeInlineTranslation($tag, $translation)
     {
@@ -370,6 +373,7 @@ class Translate
      * one provided in the constructor to be used to find the directory of the dictionary. This allows to combine
      * dictionaries inside the SimpleSAMLphp main code distribution together with external dictionaries. Defaults to
      * null.
+     * @return void
      */
     public function includeLanguageFile($file, $otherConfig = null)
     {
-- 
GitLab