]> git.mxchange.org Git - friendica.git/commitdiff
Central function to fetch the type for a given hash
authorMichael <heluecht@pirati.ca>
Sat, 18 Apr 2020 21:01:43 +0000 (21:01 +0000)
committerMichael <heluecht@pirati.ca>
Sat, 18 Apr 2020 21:01:43 +0000 (21:01 +0000)
src/Model/Tag.php

index b9e04ddd7a31865120bcec792d993df9e9f374e9..f11286e6a3aca3b49b853186db1f7fef99be093d 100644 (file)
@@ -127,15 +127,8 @@ class Tag
         */
        public static function storeByHash(int $uriid, string $hash, string $name, string $url = '')
        {
-               if ($hash == self::TAG_CHARACTER[self::MENTION]) {
-                       $type = self::MENTION;
-               } elseif ($hash == self::TAG_CHARACTER[self::EXCLUSIVE_MENTION]) {
-                       $type = self::EXCLUSIVE_MENTION;
-               } elseif ($hash == self::TAG_CHARACTER[self::IMPLICIT_MENTION]) {
-                       $type = self::IMPLICIT_MENTION;
-               } elseif ($hash == self::TAG_CHARACTER[self::HASHTAG]) {
-                       $type = self::HASHTAG;
-               } else {
+               $type = self::getTypeForHash($hash);
+               if ($type == self::UNKNOWN) {
                        return;
                }
 
@@ -192,19 +185,34 @@ class Tag
         * @param string $url
         */
        public static function removeByHash(int $uriid, string $hash, string $name, string $url = '')
+       {
+               $type = self::getTypeForHash($hash);
+               if ($type == self::UNKNOWN) {
+                       return;
+               }
+
+               self::remove($uriid, $type, $name, $url);
+       }
+
+       /**
+        * Get the type for the given hash
+        *
+        * @param string $hash
+        * @return integer type
+        */
+       private static function getTypeForHash(string $hash)
        {
                if ($hash == self::TAG_CHARACTER[self::MENTION]) {
-                       $type = self::MENTION;
+                       return self::MENTION;
                } elseif ($hash == self::TAG_CHARACTER[self::EXCLUSIVE_MENTION]) {
-                       $type = self::EXCLUSIVE_MENTION;
+                       return self::EXCLUSIVE_MENTION;
                } elseif ($hash == self::TAG_CHARACTER[self::IMPLICIT_MENTION]) {
-                       $type = self::IMPLICIT_MENTION;
+                       return self::IMPLICIT_MENTION;
                } elseif ($hash == self::TAG_CHARACTER[self::HASHTAG]) {
-                       $type = self::HASHTAG;
+                       return self::HASHTAG;
                } else {
-                       return;
+                       return self::UNKNOWN;
                }
 
-               self::remove($uriid, $type, $name, $url);
        }
 }