]> git.immae.eu Git - github/wallabag/wallabag.git/commitdiff
updateOriginUrl: rewrite some if, resolving feedbacks from PR
authorKevin Decherf <kevin@kdecherf.com>
Wed, 24 Oct 2018 19:54:09 +0000 (21:54 +0200)
committerKevin Decherf <kevin@kdecherf.com>
Wed, 24 Oct 2018 19:54:09 +0000 (21:54 +0200)
Signed-off-by: Kevin Decherf <kevin@kdecherf.com>
src/Wallabag/CoreBundle/Helper/ContentProxy.php

index 2dc436f8ec2a6c59f37b6adbb0b5a5291ebdca3d..92351986bffe6ab7e63a3999eec50987beebaa53 100644 (file)
@@ -321,43 +321,46 @@ class ContentProxy
      */
     private function updateOriginUrl(Entry $entry, $url)
     {
-        if (!empty($url) && $entry->getUrl() !== $url) {
-            $parsed_entry_url = parse_url($entry->getUrl());
-            $parsed_content_url = parse_url($url);
+        if (empty($url) || $entry->getUrl() === $url) {
+            return false;
+        }
+
+        $parsed_entry_url = parse_url($entry->getUrl());
+        $parsed_content_url = parse_url($url);
 
-            $diff_ec = array_diff_assoc($parsed_entry_url, $parsed_content_url);
-            $diff_ce = array_diff_assoc($parsed_content_url, $parsed_entry_url);
+        $diff_ec = array_diff_assoc($parsed_entry_url, $parsed_content_url);
+        $diff_ce = array_diff_assoc($parsed_content_url, $parsed_entry_url);
 
-            $diff = array_merge($diff_ec, $diff_ce);
-            $diff_keys = array_keys($diff);
-            sort($diff_keys);
+        $diff = array_merge($diff_ec, $diff_ce);
+        $diff_keys = array_keys($diff);
+        sort($diff_keys);
+
+        if ($this->ignoreUrl($entry->getUrl())) {
+            $entry->setUrl($url);
+            return false;
+        }
 
-            if ($this->ignoreUrl($entry->getUrl())) {
+        switch ($diff_keys) {
+            case ['path']:
+                if (($parsed_entry_url['path'] . '/' === $parsed_content_url['path']) // diff is trailing slash, we only replace the url of the entry
+                    || ($url === urldecode($entry->getUrl()))) { // we update entry url if new url is a decoded version of it, see EntryRepository#findByUrlAndUserId
+                    $entry->setUrl($url);
+                }
+                break;
+            case ['scheme']:
                 $entry->setUrl($url);
-            } else {
-                switch ($diff_keys) {
-                    case ['path']:
-                        if (($parsed_entry_url['path'] . '/' === $parsed_content_url['path']) // diff is trailing slash, we only replace the url of the entry
-                            || ($url === urldecode($entry->getUrl()))) { // we update entry url if new url is a decoded version of it, see EntryRepository#findByUrlAndUserId
-                            $entry->setUrl($url);
-                        }
-                        break;
-                    case ['scheme']:
-                        $entry->setUrl($url);
-                        break;
-                    case ['fragment']:
-                    case ['query']:
-                    case ['fragment', 'query']:
-                        // noop
-                        break;
-                    default:
-                        if (empty($entry->getOriginUrl())) {
-                            $entry->setOriginUrl($entry->getUrl());
-                        }
-                        $entry->setUrl($url);
-                        break;
+                break;
+            case ['fragment']:
+            case ['query']:
+            case ['fragment', 'query']:
+                // noop
+                break;
+            default:
+                if (empty($entry->getOriginUrl())) {
+                    $entry->setOriginUrl($entry->getUrl());
                 }
-            }
+                $entry->setUrl($url);
+                break;
         }
     }