Explorar o código

Update Extractor

Daniel Supernault %!s(int64=6) %!d(string=hai) anos
pai
achega
59a1346277
Modificáronse 1 ficheiros con 8 adicións e 13 borrados
  1. 8 13
      app/Util/Lexer/Extractor.php

+ 8 - 13
app/Util/Lexer/Extractor.php

@@ -10,6 +10,7 @@
 namespace App\Util\Lexer;
 
 use Illuminate\Support\Str;
+use App\Status;
 
 /**
  * Twitter Extractor Class.
@@ -121,7 +122,7 @@ class Extractor extends Regex
             $hashtagsOnly[] = $hashtagWithIndex['hashtag'];
         }
 
-        return $hashtagsOnly;
+        return array_slice($hashtagsOnly, 0, Status::MAX_HASHTAGS);
     }
 
     /**
@@ -134,12 +135,6 @@ class Extractor extends Regex
     public function extractCashtags($tweet = null)
     {
         $cashtagsOnly = [];
-        $cashtagsWithIndices = $this->extractCashtagsWithIndices($tweet);
-
-        foreach ($cashtagsWithIndices as $cashtagWithIndex) {
-            $cashtagsOnly[] = $cashtagWithIndex['cashtag'];
-        }
-
         return $cashtagsOnly;
     }
 
@@ -159,7 +154,7 @@ class Extractor extends Regex
             $urlsOnly[] = $urlWithIndex['url'];
         }
 
-        return $urlsOnly;
+        return array_slice($urlsOnly, 0, Status::MAX_LINKS);
     }
 
     /**
@@ -277,7 +272,7 @@ class Extractor extends Regex
         }
 
         if (!$checkUrlOverlap) {
-            return $tags;
+            return array_slice($tags, 0, Status::MAX_HASHTAGS);
         }
 
         // check url overlap
@@ -292,7 +287,7 @@ class Extractor extends Regex
             $validTags[] = $entity;
         }
 
-        return $validTags;
+        return array_slice($validTags, 0, Status::MAX_HASHTAGS);
     }
 
     /**
@@ -390,7 +385,7 @@ class Extractor extends Regex
             }
         }
 
-        return $urls;
+        return array_slice($urls, 0, Status::MAX_LINKS);
     }
 
     /**
@@ -415,7 +410,7 @@ class Extractor extends Regex
             $usernamesOnly[] = $mention;
         }
 
-        return $usernamesOnly;
+        return array_slice($usernamesOnly, 0, Status::MAX_MENTIONS);
     }
 
     /**
@@ -472,7 +467,7 @@ class Extractor extends Regex
             $results[] = $entity;
         }
 
-        return $results;
+        return array_slice($results, 0, Status::MAX_MENTIONS);
     }
 
     /**