| Conditions | 24 |
| Paths | 576 |
| Total Lines | 137 |
| Code Lines | 60 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| Bugs | 0 | Features | 2 |
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 |
||
| 77 | function template_view_article() |
||
| 78 | { |
||
| 79 | global $context, $txt; |
||
| 80 | |||
| 81 | echo ' |
||
| 82 | <article id="sp_view_article">'; |
||
| 83 | |||
| 84 | if (empty($context['article']['style']['no_title'])) |
||
| 85 | { |
||
| 86 | echo ' |
||
| 87 | <h1', strpos($context['article']['style']['title']['class'], 'custom') === false ? ' class="' . $context['article']['style']['title']['class'] . '"' : '', !empty($context['article']['style']['title']['style']) ? ' style="' . $context['article']['style']['title']['style'] . '"' : '', '> |
||
| 88 | ', $context['article']['title'], ' |
||
| 89 | </h1>'; |
||
| 90 | } |
||
| 91 | |||
| 92 | echo ' |
||
| 93 | <div class="sp_content_padding ', $context['article']['style']['body']['class'], '"', !empty($context['article']['style']['body']['style']) ? ' style="' . $context['article']['style']['body']['style'] . '"' : '', '> |
||
| 94 | <div class="sp_article_detail">'; |
||
| 95 | |||
| 96 | if (!empty($context['article']['author']['avatar']['image'])) |
||
| 97 | echo $context['article']['author']['avatar']['image']; |
||
| 98 | |||
| 99 | echo ' |
||
| 100 | <span class="sp_article_latest"> |
||
| 101 | ', sprintf(!empty($context['using_relative_time']) ? $txt['sp_posted_on_in_by'] : $txt['sp_posted_in_on_by'], $context['article']['category']['link'], $context['article']['date'], $context['article']['author']['link']); |
||
| 102 | |||
| 103 | if (!empty($context['article']['author']['avatar']['image'])) |
||
| 104 | echo ' |
||
| 105 | <br />'; |
||
| 106 | else |
||
| 107 | echo ' |
||
| 108 | </span> |
||
| 109 | <br /> |
||
| 110 | <span class="floatright">'; |
||
| 111 | |||
| 112 | echo ' |
||
| 113 | ', sprintf($context['article']['view_count'] == 1 ? $txt['sp_viewed_time'] : $txt['sp_viewed_times'], $context['article']['view_count']), ', ', |
||
| 114 | sprintf($context['article']['comment_count'] == 1 ? $txt['sp_commented_on_time'] : $txt['sp_commented_on_times'], $context['article']['comment_count']), ' |
||
| 115 | </span> |
||
| 116 | </div> |
||
| 117 | <div id="msg_', $context['article']['id'], '" class="messageContent inner sp_inner">' , |
||
| 118 | $context['article']['body']; |
||
| 119 | |||
| 120 | if ($context['article']['can_moderate'] && empty($context['preview'])) |
||
| 121 | echo ' |
||
| 122 | <div class="submitbutton"> |
||
| 123 | <a class="linkbutton" href="?action=admin;area=portalarticles;sa=edit;article_id=' . $context['article']['id'] . ';' . $context['session_var'] . '=' . $context['session_id'] . '" accesskey="e">' . $txt['edit'] . '</a> |
||
| 124 | <a class="linkbutton" href="?action=admin;area=portalarticles;sa=delete;article_id=' . $context['article']['id'] . ';' . $context['session_var'] . '=' . $context['session_id'] . '" onclick="return confirm(' . JavaScriptEscape($txt['quickmod_confirm']) . ') && submitThisOnce(this);" accesskey="d">' . $txt['delete'] . '</a> |
||
| 125 | </div>'; |
||
| 126 | |||
| 127 | // Assuming there are attachments... |
||
| 128 | if (!empty($context['article']['attachment'])) |
||
| 129 | { |
||
| 130 | template_sp_display_attachments($context['article'], false); |
||
| 131 | } |
||
| 132 | |||
| 133 | echo ' |
||
| 134 | </div> |
||
| 135 | </div>'; |
||
| 136 | |||
| 137 | // Not just previewing the new article, then show comments etc |
||
| 138 | if (empty($context['preview'])) |
||
| 139 | { |
||
| 140 | echo ' |
||
| 141 | <section id="sp_view_comments"> |
||
| 142 | <h3 class="category_header"> |
||
| 143 | ', $txt['sp-comments'], ' |
||
| 144 | </h3>'; |
||
| 145 | |||
| 146 | if (empty($context['article']['comments'])) |
||
| 147 | { |
||
| 148 | echo ' |
||
| 149 | <div class="infobox"> |
||
| 150 | ', $txt['error_sp_no_comments'], ' |
||
| 151 | </div>'; |
||
| 152 | } |
||
| 153 | |||
| 154 | foreach ($context['article']['comments'] as $comment) |
||
| 155 | { |
||
| 156 | echo ' |
||
| 157 | <div id="comment', $comment['id'], '" class="content"> |
||
| 158 | <div class="sp_content_padding flow_auto"> |
||
| 159 | <div class="sp_comment_detail">'; |
||
| 160 | |||
| 161 | if (!empty($comment['author']['avatar']['image'])) |
||
| 162 | echo $comment['author']['avatar']['image']; |
||
| 163 | |||
| 164 | // Show the edit icons if they are allowed |
||
| 165 | if ($comment['can_moderate']) |
||
| 166 | echo ' |
||
| 167 | <div class="floatright"> |
||
| 168 | <a href="', $context['article']['href'], ';modify=', $comment['id'], ';', $context['session_var'], '=', $context['session_id'], '#sp_comment">', sp_embed_image('modify'), '</a> |
||
| 169 | <a href="', $context['article']['href'], ';delete=', $comment['id'], ';', $context['session_var'], '=', $context['session_id'], '">', sp_embed_image('delete'), '</a> |
||
| 170 | </div>'; |
||
| 171 | |||
| 172 | echo ' |
||
| 173 | <span class="sp_article_latest">', sprintf($txt['sp_posted_by'], $comment['time'], $comment['author']['link']), '</span> |
||
| 174 | </div> |
||
| 175 | <hr /> |
||
| 176 | <p class="sp_comment_body"> |
||
| 177 | ', $comment['body'], ' |
||
| 178 | </p> |
||
| 179 | </div> |
||
| 180 | </div>'; |
||
| 181 | } |
||
| 182 | |||
| 183 | // Pages as well? |
||
| 184 | if (!empty($context['page_index'])) |
||
| 185 | template_pagesection(); |
||
| 186 | |||
| 187 | // Show the comment box |
||
| 188 | if ($context['article']['can_comment']) |
||
| 189 | { |
||
| 190 | echo ' |
||
| 191 | <section id="sp_comment" class="sp_content_padding"> |
||
| 192 | <form action="', $context['article']['href'], '" method="post" accept-charset="UTF-8"> |
||
| 193 | <textarea name="body" rows="5" cols="50" style="width: 100%;padding: 0.1em 0.2em" tabindex="', $context['tabindex']++, '">', !empty($context['article']['comment']['body']) ? $context['article']['comment']['body'] : '', '</textarea> |
||
| 194 | <div class="submitbutton"> |
||
| 195 | <input type="submit" name="submit" value="', !empty($context['article']['comment']) ? $txt['sp_modify'] : $txt['sp_submit'], '" class="right_submit" /> |
||
| 196 | <input type="hidden" name="comment" value="', !empty($context['article']['comment']['id']) ? $context['article']['comment']['id'] : 0, '" /> |
||
| 197 | <input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" /> |
||
| 198 | </div> |
||
| 199 | </form> |
||
| 200 | </section>'; |
||
| 201 | } |
||
| 202 | |||
| 203 | echo ' |
||
| 204 | </section>'; |
||
| 205 | } |
||
| 206 | |||
| 207 | echo ' |
||
| 208 | </article>'; |
||
| 209 | |||
| 210 | template_article_schema_script(); |
||
| 211 | |||
| 212 | if (!empty($context['using_relative_time'])) |
||
| 213 | addInlineJavascript('$(\'.sp_article_latest\').addClass(\'relative\');', true); |
||
| 214 | } |
||
| 326 |