]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - src/Wallabag/CoreBundle/Helper/RuleBasedTagger.php
Merge pull request #2220 from Rurik19/master
[github/wallabag/wallabag.git] / src / Wallabag / CoreBundle / Helper / RuleBasedTagger.php
index fb2d1f87d584bb8271f740ecedec49b28116e147..239d09ae7bd8ff7f13dd8aeb74d12884621476db 100644 (file)
@@ -25,7 +25,7 @@ class RuleBasedTagger
     /**
      * Add tags from rules defined by the user.
      *
-     * @param Entry $entry Entry to tag.
+     * @param Entry $entry Entry to tag
      */
     public function tag(Entry $entry)
     {
@@ -37,7 +37,7 @@ class RuleBasedTagger
             }
 
             foreach ($rule->getTags() as $label) {
-                $tag = $this->getTag($entry->getUser(), $label);
+                $tag = $this->getTag($label);
 
                 $entry->addTag($tag);
             }
@@ -49,12 +49,12 @@ class RuleBasedTagger
      *
      * @param User $user
      *
-     * @return array<Entry> A list of modified entries.
+     * @return array<Entry> A list of modified entries
      */
     public function tagAllForUser(User $user)
     {
         $rules = $this->getRulesForUser($user);
-        $entries = array();
+        $entries = [];
 
         foreach ($rules as $rule) {
             $qb = $this->entryRepository->getBuilderForAllByUser($user->getId());
@@ -62,10 +62,9 @@ class RuleBasedTagger
 
             foreach ($entries as $entry) {
                 foreach ($rule->getTags() as $label) {
-                    $tag = $this->getTag($user, $label);
+                    $tag = $this->getTag($label);
 
                     $entry->addTag($tag);
-                    $entries[] = $entry;
                 }
             }
         }
@@ -74,19 +73,18 @@ class RuleBasedTagger
     }
 
     /**
-     * Fetch a tag for a user.
+     * Fetch a tag.
      *
-     * @param User   $user
-     * @param string $label The tag's label.
+     * @param string $label The tag's label
      *
      * @return Tag
      */
-    private function getTag(User $user, $label)
+    private function getTag($label)
     {
-        $tag = $this->tagRepository->findOneByLabelAndUserId($label, $user->getId());
+        $tag = $this->tagRepository->findOneByLabel($label);
 
         if (!$tag) {
-            $tag = new Tag($user);
+            $tag = new Tag();
             $tag->setLabel($label);
         }