Conditions | 10 |
Paths | 12 |
Total Lines | 72 |
Code Lines | 43 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 1 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
94 | public function hook_fetch_feed($feed_data, $fetch_url, $owner_uid, $feed, $last_article_timestamp, $auth_login, $auth_pass) { |
||
95 | if ($auth_login || $auth_pass) { |
||
96 | return $feed_data; |
||
97 | } |
||
98 | |||
99 | if (preg_match('#^https?://(?:feeds\.feedburner\.com/uclick|www\.gocomics\.com)/([-a-z0-9]+)$#i', $fetch_url, $comic)) { |
||
100 | $site_url = 'https://www.gocomics.com/'.$comic[1]; |
||
101 | |||
102 | $article_link = $site_url.date('/Y/m/d'); |
||
103 | |||
104 | $body = fetch_file_contents(array('url' => $article_link, 'type' => 'text/html', 'followlocation' => false)); |
||
105 | |||
106 | require_once 'lib/MiniTemplator.class.php'; |
||
107 | |||
108 | $feed_title = htmlspecialchars($comic[1]); |
||
109 | $site_url = htmlspecialchars($site_url); |
||
110 | $article_link = htmlspecialchars($article_link); |
||
111 | |||
112 | $tpl = new MiniTemplator(); |
||
113 | |||
114 | $tpl->readTemplateFromFile('templates/generated_feed.txt'); |
||
115 | |||
116 | $tpl->setVariable('FEED_TITLE', $feed_title, true); |
||
117 | $tpl->setVariable('VERSION', get_version(), true); |
||
118 | $tpl->setVariable('FEED_URL', htmlspecialchars($fetch_url), true); |
||
119 | $tpl->setVariable('SELF_URL', $site_url, true); |
||
120 | |||
121 | if ($body) { |
||
122 | $doc = new DOMDocument(); |
||
123 | |||
124 | if (@$doc->loadHTML($body)) { |
||
125 | $xpath = new DOMXPath($doc); |
||
126 | |||
127 | $node = $xpath->query('//picture[contains(@class, "item-comic-image")]/img')->item(0); |
||
128 | |||
129 | if ($node) { |
||
130 | $title = $xpath->query('//h1')->item(0); |
||
131 | |||
132 | if ($title) { |
||
133 | $title = clean(trim($title->nodeValue)); |
||
134 | } else { |
||
135 | $title = date('l, F d, Y'); |
||
136 | } |
||
137 | |||
138 | foreach (['srcset', 'sizes', 'data-srcset', 'width'] as $attr) { |
||
139 | $node->removeAttribute($attr); |
||
140 | } |
||
141 | |||
142 | $tpl->setVariable('ARTICLE_ID', $article_link, true); |
||
143 | $tpl->setVariable('ARTICLE_LINK', $article_link, true); |
||
144 | $tpl->setVariable('ARTICLE_UPDATED_ATOM', date('c', mktime(11, 0, 0)), true); |
||
145 | $tpl->setVariable('ARTICLE_TITLE', htmlspecialchars($title), true); |
||
146 | $tpl->setVariable('ARTICLE_EXCERPT', '', true); |
||
147 | $tpl->setVariable('ARTICLE_CONTENT', $doc->saveHTML($node), true); |
||
148 | |||
149 | $tpl->setVariable('ARTICLE_AUTHOR', '', true); |
||
150 | $tpl->setVariable('ARTICLE_SOURCE_LINK', $site_url, true); |
||
151 | $tpl->setVariable('ARTICLE_SOURCE_TITLE', $feed_title, true); |
||
152 | |||
153 | $tpl->addBlock('entry'); |
||
154 | } |
||
155 | } |
||
156 | } |
||
157 | |||
158 | $tpl->addBlock('feed'); |
||
159 | |||
160 | if ($tpl->generateOutputToString($tmp_data)) { |
||
161 | $feed_data = $tmp_data; |
||
162 | } |
||
163 | } |
||
164 | |||
165 | return $feed_data; |
||
166 | } |
||
198 |