]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - lib/nickname.php
Better use of Nickname validation functions
[quix0rs-gnu-social.git] / lib / nickname.php
index 2b8249d59ab4b6ab7ff01099386cf7c94b55d491..2792d32fd50494900a01e4cbf09a55617d1fab5c 100644 (file)
@@ -110,30 +110,25 @@ class Nickname
      */
     public static function normalize($str, $checkuse=false)
     {
-        if (mb_strlen($str) > self::MAX_LEN) {
-            // Display forms must also fit!
-            throw new NicknameTooLongException();
-        }
-
+        // We should also have UTF-8 normalization (å to a etc.)
         $str = trim($str);
         $str = str_replace('_', '', $str);
         $str = mb_strtolower($str);
 
-        if (mb_strlen($str) < 1) {
+        if (mb_strlen($str) > self::MAX_LEN) {
+            // Display forms must also fit!
+            throw new NicknameTooLongException();
+        } elseif (mb_strlen($str) < 1) {
             throw new NicknameEmptyException();
-        }
-        if (!self::isCanonical($str)) {
+        } elseif (!self::isCanonical($str)) {
             throw new NicknameInvalidException();
-        }
-        if (self::isBlacklisted($str)) {
+        } elseif (self::isBlacklisted($str)) {
             throw new NicknameBlacklistedException();
-        }
-        if (self::isSystemPath($str)) {
+        } elseif (self::isSystemPath($str)) {
             throw new NicknamePathCollisionException();
-        }
-        if ($checkuse && $user = self::isTaken($str)) {
+        } elseif ($checkuse && $user = self::isTaken($str)) {
             if ($user instanceof User) {
-                throw new NicknameTakenException();
+                throw new NicknameTakenException($user);
             }
         }