aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/CoreBundle/Helper/ContentProxy.php
diff options
context:
space:
mode:
authorJeremy Benoist <jeremy.benoist@gmail.com>2016-03-27 20:35:56 +0200
committerJeremy Benoist <jeremy.benoist@gmail.com>2016-03-27 20:54:57 +0200
commit4d0ec0e72108ff47952906e5d968a7c3eb0a76f9 (patch)
treeb8e9cd86010368631296c22a2352f5dbedb429a1 /src/Wallabag/CoreBundle/Helper/ContentProxy.php
parent5d6f6f56a2a0f72a67c2d3f96eb61986cf821a1e (diff)
downloadwallabag-4d0ec0e72108ff47952906e5d968a7c3eb0a76f9.tar.gz
wallabag-4d0ec0e72108ff47952906e5d968a7c3eb0a76f9.tar.zst
wallabag-4d0ec0e72108ff47952906e5d968a7c3eb0a76f9.zip
Fix some Scrutinizer issues
Diffstat (limited to 'src/Wallabag/CoreBundle/Helper/ContentProxy.php')
-rw-r--r--src/Wallabag/CoreBundle/Helper/ContentProxy.php34
1 files changed, 29 insertions, 5 deletions
diff --git a/src/Wallabag/CoreBundle/Helper/ContentProxy.php b/src/Wallabag/CoreBundle/Helper/ContentProxy.php
index ba90b731..ed4a220d 100644
--- a/src/Wallabag/CoreBundle/Helper/ContentProxy.php
+++ b/src/Wallabag/CoreBundle/Helper/ContentProxy.php
@@ -32,14 +32,21 @@ class ContentProxy
32 * Fetch content using graby and hydrate given entry with results information. 32 * Fetch content using graby and hydrate given entry with results information.
33 * In case we couldn't find content, we'll try to use Open Graph data. 33 * In case we couldn't find content, we'll try to use Open Graph data.
34 * 34 *
35 * @param Entry $entry Entry to update 35 * We can also force the content, in case of an import from the v1 for example, so the function won't
36 * @param string $url Url to grab content for 36 * fetch the content from the website but rather use information given with the $content parameter.
37 *
38 * @param Entry $entry Entry to update
39 * @param string $url Url to grab content for
40 * @param array $content An array with AT LEAST keys title, html, url, language & content_type to skip the fetchContent from the url
37 * 41 *
38 * @return Entry 42 * @return Entry
39 */ 43 */
40 public function updateEntry(Entry $entry, $url) 44 public function updateEntry(Entry $entry, $url, array $content = [])
41 { 45 {
42 $content = $this->graby->fetchContent($url); 46 // do we have to fetch the content or the provided one is ok?
47 if (empty($content) || false === $this->validateContent($content)) {
48 $content = $this->graby->fetchContent($url);
49 }
43 50
44 $title = $content['title']; 51 $title = $content['title'];
45 if (!$title && isset($content['open_graph']['og_title'])) { 52 if (!$title && isset($content['open_graph']['og_title'])) {
@@ -62,7 +69,11 @@ class ContentProxy
62 $entry->setLanguage($content['language']); 69 $entry->setLanguage($content['language']);
63 $entry->setMimetype($content['content_type']); 70 $entry->setMimetype($content['content_type']);
64 $entry->setReadingTime(Utils::getReadingTime($html)); 71 $entry->setReadingTime(Utils::getReadingTime($html));
65 $entry->setDomainName(parse_url($entry->getUrl(), PHP_URL_HOST)); 72
73 $domainName = parse_url($entry->getUrl(), PHP_URL_HOST);
74 if (false !== $domainName) {
75 $entry->setDomainName($domainName);
76 }
66 77
67 if (isset($content['open_graph']['og_image'])) { 78 if (isset($content['open_graph']['og_image'])) {
68 $entry->setPreviewPicture($content['open_graph']['og_image']); 79 $entry->setPreviewPicture($content['open_graph']['og_image']);
@@ -113,4 +124,17 @@ class ContentProxy
113 } 124 }
114 } 125 }
115 } 126 }
127
128 /**
129 * Validate that the given content as enough value to be used
130 * instead of fetch the content from the url.
131 *
132 * @param array $content
133 *
134 * @return bool true if valid otherwise false
135 */
136 private function validateContent(array $content)
137 {
138 return isset($content['title']) && isset($content['html']) && isset($content['url']) && isset($content['language']) && isset($content['content_type']);
139 }
116} 140}