Conditions | 2 |
Paths | 2 |
Total Lines | 78 |
Code Lines | 47 |
Lines | 3 |
Ratio | 3.85 % |
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 |
||
31 | function PrintPage($articleID) |
||
32 | { |
||
33 | global $moduleDirName; |
||
34 | global $xoopsConfig, $xoopsModule, $xoopsModuleConfig; |
||
35 | $myts = MyTextSanitizer:: getInstance(); |
||
36 | $articleID = (int)$articleID; |
||
37 | //get entry object |
||
38 | $entrydataHandler = xoops_getModuleHandler('entryget', $moduleDirName); |
||
39 | $_entryob = $entrydataHandler->getArticleOnePermcheck($articleID, true, true); |
||
40 | View Code Duplication | if (!is_object($_entryob)) { |
|
41 | redirect_header(XOOPS_URL . '/modules/' . $moduleDirName . '/index.php', 1, 'Not Found'); |
||
42 | } |
||
43 | //------------------------------------- |
||
44 | $articles = $_entryob->toArray(); |
||
45 | //get category object |
||
46 | $_categoryob = $_entryob->_sbcolumns; |
||
47 | //get vars |
||
48 | $category = $_categoryob->toArray(); |
||
49 | //------------------------------------- |
||
50 | //get author |
||
51 | $authorname = SoapboxUtility::getAuthorName($category['author']); |
||
52 | //------------------------------------- |
||
53 | |||
54 | $datetime = $myts->htmlSpecialChars(formatTimestamp($articles['datesub'], $xoopsModuleConfig['dateformat'])); |
||
55 | // $lead = $myts->htmlSpecialChars($lead); |
||
56 | // $bodytext = str_replace("[pagebreak]","<br style=\"page-break-after:always;\">",$bodytext); |
||
57 | // $bodytext = $myts->displayTarea($bodytext, $html, $smiley, $xcodes, '', $breaks); |
||
58 | $bodytext = str_replace('[pagebreak]', '<br style="page-break-after:always;">', $_entryob->getVar('bodytext', 'none')); |
||
59 | $bodytext = $GLOBALS['SoapboxCleantags']->cleanTags($myts->displayTarea($bodytext, $articles['html'], $articles['smiley'], $articles['xcodes'], '', $articles['breaks'])); |
||
60 | |||
61 | $sitename = $myts->htmlSpecialChars($xoopsConfig['sitename']); |
||
62 | $slogan = $myts->htmlSpecialChars($xoopsConfig['slogan']); |
||
63 | |||
64 | echo "<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN'>\n"; |
||
65 | echo "<html>\n<head>\n"; |
||
66 | echo '<title>' . $sitename . "</title>\n"; |
||
67 | echo "<meta http-equiv='Content-Type' content='text/html; charset=" . _CHARSET . "' />\n"; |
||
68 | echo "<meta name='AUTHOR' content='" . $sitename . "' />\n"; |
||
69 | echo "<meta name='COPYRIGHT' content='Copyright (c) 2004 by " . $sitename . "' />\n"; |
||
70 | echo "<meta name='DESCRIPTION' content='" . $slogan . "' />\n"; |
||
71 | echo "<meta name='GENERATOR' content='" . XOOPS_VERSION . "' />\n\n\n"; |
||
72 | |||
73 | //hack start 2003-3-18 by toshimitsu |
||
74 | //Column: --> _MD_SOAPBOX_COLUMNPRN , Author: --> _MD_SOAPBOX_AUTHORPRN |
||
75 | echo "<body bgcolor='#ffffff' text='#000000'> |
||
76 | <div style='width: 600px; border: 1px solid #000; padding: 20px;'> |
||
77 | <div style='text-align: center; display: block; padding-bottom: 12px; margin: 0 0 6px 0; border-bottom: 2px solid #ccc;'><img src='" |
||
78 | . XOOPS_URL |
||
79 | . '/modules/' |
||
80 | . $xoopsModule->dirname() |
||
81 | . "/assets/images/sb_slogo.png' border='0' alt='' /><h2 style='margin: 0;'>" |
||
82 | . $articles['headline'] |
||
83 | . '</h2></div> |
||
84 | <div></div> |
||
85 | <div>' |
||
86 | . _MD_SOAPBOX_COLUMNPRN |
||
87 | . '<b>' |
||
88 | . $category['name'] |
||
89 | . "</b></div> |
||
90 | <div style='padding-bottom: 6px; border-bottom: 1px solid #ccc;'>" |
||
91 | . _MD_SOAPBOX_AUTHORPRN |
||
92 | . ' <b>' |
||
93 | . $authorname |
||
94 | . '</b></div> |
||
95 | <p>' |
||
96 | . $articles['lead'] |
||
97 | . '</p> |
||
98 | <p>' |
||
99 | . $articles['bodytext'] |
||
100 | . "</p> |
||
101 | <div style='padding-top: 12px; border-top: 2px solid #ccc;'><small><b>Published: </b> " |
||
102 | . $datetime |
||
103 | . '<br></div> |
||
104 | </div> |
||
105 | <br> |
||
106 | </body> |
||
107 | </html>'; |
||
108 | } |
||
109 | |||
111 |
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.