| Conditions | 4 |
| Paths | 8 |
| Total Lines | 200 |
| Code Lines | 42 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 84 | function PrintPage() |
||
| 85 | { |
||
| 86 | global $xoopsConfig, $xoopsModule, $story, $xoops_meta_keywords, $xoops_meta_description; |
||
| 87 | $myts = MyTextSanitizer::getInstance(); |
||
| 88 | $datetime = formatTimestamp($story->published(), NewsUtility::getModuleOption('dateformat')); ?> |
||
| 89 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" |
||
| 90 | "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
||
| 91 | <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php echo _LANGCODE; ?>" lang="<?php echo _LANGCODE; ?>"> |
||
| 92 | <?php |
||
| 93 | echo "<head>\n"; |
||
| 94 | echo '<title>' . $myts->htmlSpecialChars($story->title()) . ' - ' . _NW_PRINTER . ' - ' . $myts->htmlSpecialChars($story->topic_title()) . ' - ' . $xoopsConfig['sitename'] . '</title>'; |
||
| 95 | echo '<meta http-equiv="Content-Type" content="text/html; charset=' . _CHARSET . '">'; |
||
| 96 | echo '<meta name="author" content="XOOPS">'; |
||
| 97 | echo '<meta name="keywords" content="' . $xoops_meta_keywords . '">'; |
||
| 98 | echo '<meta name="COPYRIGHT" content="Copyright (c) 2014 by ' . $xoopsConfig['sitename'] . '">'; |
||
| 99 | echo '<meta name="DESCRIPTION" content="' . $xoops_meta_description . '">'; |
||
| 100 | echo '<meta name="generator" content="XOOPS">'; |
||
| 101 | echo '<meta name="robots" content="noindex,nofollow">'; |
||
| 102 | if (file_exists(XOOPS_ROOT_PATH . '/language/' . $GLOBALS['xoopsConfig']['language'] . '/style.css')) { |
||
| 103 | echo '<link rel="stylesheet" type="text/css" media="all" title="Style sheet" href="' . XOOPS_URL . '/language/' . $GLOBALS['xoopsConfig']['language'] . '/style.css">'; |
||
| 104 | } else { |
||
| 105 | echo '<link rel="stylesheet" type="text/css" media="all" title="Style sheet" href="' . XOOPS_URL . '/language/english/style.css">'; |
||
| 106 | } |
||
| 107 | echo '<link rel="stylesheet" type="text/css" media="all" title="Style sheet" href="' . XOOPS_URL . '/modules/news/assets/css/print.css">'; |
||
| 108 | $supplemental = ''; |
||
| 109 | if (NewsUtility::getModuleOption('footNoteLinks')) { |
||
| 110 | $supplemental = "footnoteLinks('content','content'); "; ?> |
||
| 111 | <script type="text/javascript"> |
||
| 112 | // <![CDATA[ |
||
| 113 | /*------------------------------------------------------------------------------ |
||
| 114 | Function: footnoteLinks() |
||
| 115 | Author: Aaron Gustafson (aaron at easy-designs dot net) |
||
| 116 | Creation Date: 8 May 2005 |
||
| 117 | Version: 1.3 |
||
| 118 | Homepage: http://www.easy-designs.net/code/footnoteLinks/ |
||
| 119 | License: Creative Commons Attribution-ShareAlike 2.0 License |
||
| 120 | http://creativecommons.org/licenses/by-sa/2.0/ |
||
| 121 | Note: This version has reduced functionality as it is a demo of |
||
| 122 | the script's development |
||
| 123 | ------------------------------------------------------------------------------*/ |
||
| 124 | function footnoteLinks(containerID, targetID) { |
||
| 125 | if (!document.getElementById || !document.getElementsByTagName || !document.createElement) return false; |
||
| 126 | if (!document.getElementById(containerID) || !document.getElementById(targetID)) return false; |
||
| 127 | var container = document.getElementById(containerID); |
||
| 128 | var target = document.getElementById(targetID); |
||
| 129 | var h2 = document.createElement('h2'); |
||
| 130 | addClass.apply(h2, ['printOnly']); |
||
| 131 | var h2_txt = document.createTextNode('<?php echo _NW_LINKS; ?>'); |
||
| 132 | h2.appendChild(h2_txt); |
||
| 133 | var coll = container.getElementsByTagName('*'); |
||
| 134 | var ol = document.createElement('ol'); |
||
| 135 | addClass.apply(ol, ['printOnly']); |
||
| 136 | var myArr = []; |
||
| 137 | var thisLink; |
||
| 138 | var num = 1; |
||
| 139 | for (var i = 0; i < coll.length; i++) { |
||
| 140 | if (coll[i].getAttribute('href') || |
||
| 141 | coll[i].getAttribute('cite')) { |
||
| 142 | thisLink = coll[i].getAttribute('href') ? coll[i].href : coll[i].cite; |
||
| 143 | var note = document.createElement('sup'); |
||
| 144 | addClass.apply(note, ['printOnly']); |
||
| 145 | var note_txt; |
||
| 146 | var j = inArray.apply(myArr, [thisLink]); |
||
| 147 | if (j || j === 0) { // if a duplicate |
||
| 148 | // get the corresponding number from |
||
| 149 | // the array of used links |
||
| 150 | note_txt = document.createTextNode(j + 1); |
||
| 151 | } else { // if not a duplicate |
||
| 152 | var li = document.createElement('li'); |
||
| 153 | var li_txt = document.createTextNode(thisLink); |
||
| 154 | li.appendChild(li_txt); |
||
| 155 | ol.appendChild(li); |
||
| 156 | myArr.push(thisLink); |
||
| 157 | note_txt = document.createTextNode(num); |
||
| 158 | num++; |
||
| 159 | } |
||
| 160 | note.appendChild(note_txt); |
||
| 161 | if (coll[i].tagName.toLowerCase() === 'blockquote') { |
||
| 162 | var lastChild = lastChildContainingText.apply(coll[i]); |
||
| 163 | lastChild.appendChild(note); |
||
| 164 | } else { |
||
| 165 | coll[i].parentNode.insertBefore(note, coll[i].nextSibling); |
||
| 166 | } |
||
| 167 | } |
||
| 168 | } |
||
| 169 | target.appendChild(h2); |
||
| 170 | target.appendChild(ol); |
||
| 171 | |||
| 172 | return true; |
||
| 173 | } |
||
| 174 | |||
| 175 | // ]]> |
||
| 176 | </script> |
||
| 177 | <script type="text/javascript"> |
||
| 178 | // <![CDATA[ |
||
| 179 | /*------------------------------------------------------------------------------ |
||
| 180 | Excerpts from the jsUtilities Library |
||
| 181 | Version: 2.1 |
||
| 182 | Homepage: http://www.easy-designs.net/code/jsUtilities/ |
||
| 183 | License: Creative Commons Attribution-ShareAlike 2.0 License |
||
| 184 | http://creativecommons.org/licenses/by-sa/2.0/ |
||
| 185 | Note: If you change or improve on this script, please let us know. |
||
| 186 | ------------------------------------------------------------------------------*/ |
||
| 187 | if (Array.prototype.push === null) { |
||
| 188 | Array.prototype.push = function (item) { |
||
| 189 | this[this.length] = item; |
||
| 190 | |||
| 191 | return this.length; |
||
| 192 | }; |
||
| 193 | } |
||
| 194 | // --------------------------------------------------------------------- |
||
| 195 | // function.apply (if unsupported) |
||
| 196 | // Courtesy of Aaron Boodman - http://youngpup.net |
||
| 197 | // --------------------------------------------------------------------- |
||
| 198 | if (!Function.prototype.apply) { |
||
| 199 | Function.prototype.apply = function (oScope, args) { |
||
| 200 | var sarg = []; |
||
| 201 | var rtrn, call; |
||
| 202 | if (!oScope) oScope = window; |
||
| 203 | if (!args) args = []; |
||
| 204 | for (var i = 0; i < args.length; i++) { |
||
| 205 | sarg[i] = "args[" + i + "]"; |
||
| 206 | } |
||
| 207 | call = "oScope.__applyTemp__(" + sarg.join(",") + ");"; |
||
| 208 | oScope.__applyTemp__ = this; |
||
| 209 | rtrn = eval(call); |
||
| 210 | oScope.__applyTemp__ = null; |
||
| 211 | |||
| 212 | return rtrn; |
||
| 213 | }; |
||
| 214 | } |
||
| 215 | |||
| 216 | function inArray(needle) { |
||
| 217 | for (var i = 0; i < this.length; i++) { |
||
| 218 | if (this[i] === needle) { |
||
| 219 | return i; |
||
| 220 | } |
||
| 221 | } |
||
| 222 | |||
| 223 | return false; |
||
| 224 | } |
||
| 225 | |||
| 226 | function addClass(theClass) { |
||
| 227 | if (this.className !== '') { |
||
| 228 | this.className += ' ' + theClass; |
||
| 229 | } else { |
||
| 230 | this.className = theClass; |
||
| 231 | } |
||
| 232 | } |
||
| 233 | |||
| 234 | function lastChildContainingText() { |
||
| 235 | var testChild = this.lastChild; |
||
| 236 | var contentCntnr = ['p', 'li', 'dd']; |
||
| 237 | while (testChild.nodeType != 1) { |
||
| 238 | testChild = testChild.previousSibling; |
||
| 239 | } |
||
| 240 | var tag = testChild.tagName.toLowerCase(); |
||
| 241 | var tagInArr = inArray.apply(contentCntnr, [tag]); |
||
| 242 | if (!tagInArr && tagInArr !== 0) { |
||
| 243 | testChild = lastChildContainingText.apply(testChild); |
||
| 244 | } |
||
| 245 | |||
| 246 | return testChild; |
||
| 247 | } |
||
| 248 | |||
| 249 | // ]]> |
||
| 250 | </script> |
||
| 251 | <style type="text/css" media="screen"> |
||
| 252 | .printOnly { |
||
| 253 | display: none; |
||
| 254 | } |
||
| 255 | </style> |
||
| 256 | <?php |
||
| 257 | } |
||
| 258 | echo '</head>'; |
||
| 259 | echo '<body bgcolor="#ffffff" text="#000000" onload="' . $supplemental . ' window.print()"> |
||
| 260 | <div id="content"> |
||
| 261 | <table border="0"><tr><td align="center"> |
||
| 262 | <table border="0" width="100%" cellpadding="0" cellspacing="1" bgcolor="#000000"><tr><td> |
||
| 263 | <table border="0" width="100%" cellpadding="20" cellspacing="1" bgcolor="#ffffff"><tr><td align="center"> |
||
| 264 | <img src="' . XOOPS_URL . '/images/logo.png" border="0" alt=""><br><br> |
||
| 265 | <h3>' . $story->title() . '</h3> |
||
| 266 | <small><b>' . _NW_DATE . '</b> ' . $datetime . ' | <b>' . _NW_TOPICC . '</b> ' . $myts->htmlSpecialChars($story->topic_title()) . '</small><br><br></td></tr>'; |
||
| 267 | echo '<tr valign="top" style="font:12px;"><td>' . $story->hometext() . '<br>'; |
||
| 268 | $bodytext = $story->bodytext(); |
||
| 269 | $bodytext = str_replace('[pagebreak]', '<br style="page-break-after:always;">', $bodytext); |
||
| 270 | if ('' !== $bodytext) { |
||
| 271 | echo $bodytext . '<br><br>'; |
||
| 272 | } |
||
| 273 | echo '</td></tr></table></td></tr></table> |
||
| 274 | <br><br>'; |
||
| 275 | printf(_NW_THISCOMESFROM, htmlspecialchars($xoopsConfig['sitename'], ENT_QUOTES)); |
||
| 276 | echo '<br><a href="' . XOOPS_URL . '/">' . XOOPS_URL . '</a><br><br> |
||
| 277 | ' . _NW_URLFORSTORY . ' <!-- Tag below can be used to display Permalink image --><!--img src="' . XOOPS_URL . '/modules/' . $xoopsModule->dirname() . '/assets/images/x.gif" /--><br> |
||
| 278 | <a class="ignore" href="' . XOOPS_URL . '/modules/' . $xoopsModule->dirname() . '/article.php?storyid=' . $story->storyid() . '">' . XOOPS_URL . '/modules/news/article.php?storyid=' . $story->storyid() . '</a> |
||
| 279 | </td></tr></table></div> |
||
| 280 | </body> |
||
| 281 | </html> |
||
| 282 | '; |
||
| 283 | } |
||
| 284 | |||
| 286 |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.