Conditions | 1 |
Paths | 1 |
Total Lines | 176 |
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 |
||
119 | function xnewsletter_printPage($content) |
||
120 | { |
||
121 | global $xoopsConfig, $xoops_meta_keywords, $xoops_meta_description; |
||
122 | $myts = \MyTextSanitizer::getInstance(); ?> |
||
123 | <!DOCTYPE html> |
||
124 | <html xml:lang="<?php echo _LANGCODE; ?>" lang="<?php echo _LANGCODE; ?>"> |
||
125 | <?php |
||
126 | echo "<head>\n"; |
||
127 | echo "<title>{$xoopsConfig['sitename']}</title>\n"; |
||
128 | echo "<meta http-equiv='Content-Type' content='text/html; charset=UTF-8'>\n"; |
||
129 | echo "<meta name='AUTHOR' content='{$xoopsConfig['sitename']}'>\n"; |
||
130 | echo "<meta name='keywords' content='{$xoops_meta_keywords}'>\n"; |
||
131 | echo "<meta name='COPYRIGHT' content='Copyright (c) " . date('Y') . " by {$xoopsConfig['sitename']}'>\n"; |
||
132 | echo "<meta name='DESCRIPTION' content='{$xoops_meta_description}'>\n"; |
||
133 | echo "<meta name='GENERATOR' content='XOOPS'>\n"; |
||
134 | echo "<!-- Sheet Css -->\n"; |
||
135 | echo "<link rel='stylesheet' type='text/css' media='all' title='Style sheet' href='" . XOOPS_URL . "'/xoops.css'>\n"; |
||
136 | echo "<link rel='stylesheet' type='text/css' media='all' title='Style sheet' href='" . XOOPS_URL . "'/themes/default/style.css'>\n"; |
||
137 | echo "<link rel='stylesheet' type='text/css' media='all' title='Style sheet' href='" . XOOPS_URL . "'/modules/xnewsletter/assets/css/module.css'>\n"; ?> |
||
138 | <script type="text/javascript"> |
||
139 | // <![CDATA[ |
||
140 | /*------------------------------------------------------------------------------ |
||
141 | Function: footnoteLinks() |
||
142 | Author: Aaron Gustafson (aaron at easy-designs dot net) |
||
143 | Creation Date: 8 May 2005 |
||
144 | Version: 1.3 |
||
145 | Homepage: http://www.easy-designs.net/code/footnoteLinks/ |
||
146 | License: Creative Commons Attribution-ShareAlike 2.0 License |
||
147 | http://creativecommons.org/licenses/by-sa/2.0/ |
||
148 | Note: This version has reduced functionality as it is a demo of |
||
149 | the script's development |
||
150 | ------------------------------------------------------------------------------*/ |
||
151 | function footnoteLinks(containerID, targetID) { |
||
152 | if (!document.getElementById || !document.getElementsByTagName || !document.createElement) return false; |
||
153 | if (!document.getElementById(containerID) || !document.getElementById(targetID)) return false; |
||
154 | var container = document.getElementById(containerID); |
||
155 | var target = document.getElementById(targetID); |
||
156 | var h2 = document.createElement('h2'); |
||
157 | addClass.apply(h2, ['printOnly']); |
||
158 | var h2_txt = document.createTextNode('<?php echo '_MA_NW_LINKS'; ?>'); |
||
159 | h2.appendChild(h2_txt); |
||
160 | var coll = container.getElementsByTagName('*'); |
||
161 | var ol = document.createElement('ol'); |
||
162 | addClass.apply(ol, ['printOnly']); |
||
163 | var myArr = []; |
||
164 | var thisLink; |
||
165 | var num = 1; |
||
166 | for (var i = 0; i < coll.length; i++) { |
||
167 | if (coll[i].getAttribute('href') || |
||
168 | coll[i].getAttribute('cite')) { |
||
169 | thisLink = coll[i].getAttribute('href') ? coll[i].href : coll[i].cite; |
||
170 | var note = document.createElement('sup'); |
||
171 | addClass.apply(note, ['printOnly']); |
||
172 | var note_txt; |
||
173 | var j = inArray.apply(myArr, [thisLink]); |
||
174 | if (j || j === 0) { // if a duplirolee |
||
175 | // get the corresponding number from |
||
176 | // the array of used links |
||
177 | note_txt = document.createTextNode(j + 1); |
||
178 | } else { |
||
179 | // if not a duplirolee |
||
180 | var li = document.createElement('li'); |
||
181 | var li_txt = document.createTextNode(thisLink); |
||
182 | li.appendChild(li_txt); |
||
183 | ol.appendChild(li); |
||
184 | myArr.push(thisLink); |
||
185 | note_txt = document.createTextNode(num); |
||
186 | num++; |
||
187 | } |
||
188 | note.appendChild(note_txt); |
||
189 | if (coll[i].tagName.toLowerCase() == 'blockquote') { |
||
190 | var lastChild = lastChildContainingText.apply(coll[i]); |
||
191 | lastChild.appendChild(note); |
||
192 | } else { |
||
193 | coll[i].parentNode.insertBefore(note, coll[i].nextSibling); |
||
194 | } |
||
195 | } |
||
196 | } |
||
197 | target.appendChild(h2); |
||
198 | target.appendChild(ol); |
||
199 | |||
200 | return true; |
||
201 | } |
||
202 | |||
203 | // ]]> |
||
204 | </script> |
||
205 | <script type="text/javascript"> |
||
206 | // <![CDATA[ |
||
207 | /*------------------------------------------------------------------------------ |
||
208 | Excerpts from the jsUtilities Library |
||
209 | Version: 2.1 |
||
210 | Homepage: http://www.easy-designs.net/code/jsUtilities/ |
||
211 | License: Creative Commons Attribution-ShareAlike 2.0 License |
||
212 | http://creativecommons.org/licenses/by-sa/2.0/ |
||
213 | Note: If you change or improve on this script, please let us know. |
||
214 | ------------------------------------------------------------------------------*/ |
||
215 | if (Array.prototype.push === null) { |
||
216 | Array.prototype.push = function (item) { |
||
217 | this[this.length] = item; |
||
218 | |||
219 | return this.length; |
||
220 | }; |
||
221 | } |
||
222 | ; |
||
223 | // --------------------------------------------------------------------- |
||
224 | // function.apply (if unsupported) |
||
225 | // Courtesy of Aaron Boodman - http://youngpup.net |
||
226 | // --------------------------------------------------------------------- |
||
227 | if (!Function.prototype.apply) { |
||
228 | Function.prototype.apply = function (oScope, args) { |
||
229 | var sarg = []; |
||
230 | var rtrn, call; |
||
231 | if (!oScope) oScope = window; |
||
232 | if (!args) args = []; |
||
233 | for (var i = 0; i < args.length; i++) { |
||
234 | sarg[i] = "args[" + i + "]"; |
||
235 | } |
||
236 | ; |
||
237 | call = "oScope.__applyTemp__(" + sarg.join(",") + ");"; |
||
238 | oScope.__applyTemp__ = this; |
||
239 | rtrn = eval(call); |
||
240 | oScope.__applyTemp__ = null; |
||
241 | |||
242 | return rtrn; |
||
243 | }; |
||
244 | } |
||
245 | ; |
||
246 | |||
247 | function inArray(needle) { |
||
248 | for (var i = 0; i < this.length; i++) { |
||
249 | if (this[i] === needle) { |
||
250 | return i; |
||
251 | } |
||
252 | } |
||
253 | |||
254 | return false; |
||
255 | } |
||
256 | |||
257 | function addClass(theClass) { |
||
258 | if (this.className != '') { |
||
259 | this.className += ' ' + theClass; |
||
260 | } else { |
||
261 | this.className = theClass; |
||
262 | } |
||
263 | } |
||
264 | |||
265 | function lastChildContainingText() { |
||
266 | var testChild = this.lastChild; |
||
267 | var contentCntnr = ['p', 'li', 'dd']; |
||
268 | while (testChild.nodeType != 1) { |
||
269 | testChild = testChild.previousSibling; |
||
270 | } |
||
271 | var tag = testChild.tagName.toLowerCase(); |
||
272 | var tagInArr = inArray.apply(contentCntnr, [tag]); |
||
273 | if (!tagInArr && tagInArr !== 0) { |
||
274 | testChild = lastChildContainingText.apply(testChild); |
||
275 | } |
||
276 | |||
277 | return testChild; |
||
278 | } |
||
279 | |||
280 | // ]]> |
||
281 | </script> |
||
282 | <style type="text/css" media="screen"> |
||
283 | .printOnly { |
||
284 | display: none; |
||
285 | } |
||
286 | </style> |
||
287 | </head> |
||
288 | <body bgcolor="#ffffff" text="#000000" onload="window.print()"> |
||
289 | <?php |
||
290 | echo $content; ?> |
||
291 | </body> |
||
292 | </html> |
||
293 | <?php |
||
294 | } |
||
295 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.