From 7528f09e45620c388b9185bf6014f64f1179893c Mon Sep 17 00:00:00 2001
From: Jaime Perez Crespo <jaime.perez@uninett.no>
Date: Tue, 9 Feb 2016 11:49:22 +0100
Subject: [PATCH] Reduce complexity in some of the methods of
 SimpleSAML\Locale\Language.

---
 lib/SimpleSAML/Locale/Language.php | 19 ++++++-------------
 1 file changed, 6 insertions(+), 13 deletions(-)

diff --git a/lib/SimpleSAML/Locale/Language.php b/lib/SimpleSAML/Locale/Language.php
index b8be4a30e..3f0387fbd 100644
--- a/lib/SimpleSAML/Locale/Language.php
+++ b/lib/SimpleSAML/Locale/Language.php
@@ -117,8 +117,7 @@ class Language
         }
 
         // run custom getLanguage function if defined
-        if (isset($this->customFunction)) {
-            assert('is_callable($customFunction)');
+        if (isset($this->customFunction) && is_callable($this->customFunction)) {
             $customLanguage = call_user_func($this->customFunction, $this);
             if ($customLanguage !== null && $customLanguage !== false) {
                 return $customLanguage;
@@ -216,12 +215,10 @@ class Language
      */
     public function getLanguageList()
     {
-        $thisLang = $this->getLanguage();
-        $lang = array();
-        foreach ($this->availableLanguages as $nl) {
-            $lang[$nl] = ($nl == $thisLang);
-        }
-        return $lang;
+        $current = $this->getLanguage();
+        $list = array_fill_keys($this->availableLanguages, false);
+        $list[$current] = true;
+        return $list;
     }
 
 
@@ -232,11 +229,7 @@ class Language
      */
     public function isLanguageRTL()
     {
-        $thisLang = $this->getLanguage();
-        if (in_array($thisLang, $this->rtlLanguages)) {
-            return true;
-        }
-        return false;
+        return in_array($this->getLanguage(), $this->rtlLanguages);
     }
 
 
-- 
GitLab