Conditions | 17 |
Paths | 1280 |
Total Lines | 120 |
Code Lines | 77 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | 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 |
||
14 | function b_lxspot_show( $options ) |
||
15 | { |
||
16 | global $xoopsDB, $xoopsUser; |
||
17 | $myts = & MyTextSanitizer :: getInstance(); |
||
18 | xoops_load('XoopsUserUtility'); |
||
19 | |||
20 | $module_name = 'lexikon' ; |
||
21 | $module_handler = &xoops_gethandler('module'); |
||
22 | $lexikon = &$module_handler->getByDirname('lexikon'); |
||
23 | if (!isset($lxConfig)) { |
||
24 | $config_handler = &xoops_gethandler('config'); |
||
25 | $lxConfig = &$config_handler->getConfigsByCat(0, $lexikon->getVar('mid')); |
||
26 | } |
||
27 | |||
28 | $gperm_handler =& xoops_gethandler('groupperm'); |
||
29 | $groups = is_object($xoopsUser) ? $xoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS; |
||
30 | $module_id = $lexikon->getVar('mid'); |
||
31 | /*$allowed_cats = $gperm_handler->getItemIds("lexikon_view", $groups, $module_id); |
||
32 | $catids = implode(',', $allowed_cats); |
||
33 | $catperms = " AND categoryID IN ($catids) ";*/ |
||
34 | |||
35 | $block = array(); |
||
36 | |||
37 | // To handle options in the template |
||
38 | if ( $options[2] == 1 ) { |
||
39 | $block['showdateask'] = 1; |
||
40 | } else { |
||
41 | $block['showdateask'] = 0; |
||
42 | } |
||
43 | if ( $options[3] == 1 ) { |
||
44 | $block['showbylineask'] = 1; |
||
45 | } else { |
||
46 | $block['showbylineask'] = 0; |
||
47 | } |
||
48 | if ( $options[4] == 1 ) { |
||
49 | $block['showstatsask'] = 1; |
||
50 | } else { |
||
51 | $block['showstatsask'] = 0; |
||
52 | } |
||
53 | if ( $options[5] == 'ver' ) { |
||
54 | $block['verticaltemplate'] = 1; |
||
55 | } else { |
||
56 | $block['verticaltemplate'] = 0; |
||
57 | } |
||
58 | if ( $options[6] == 1 ) { |
||
59 | $block['showpicask'] = 1; |
||
60 | } else { |
||
61 | $block['showpicask'] = 0; |
||
62 | } |
||
63 | |||
64 | // Retrieve the latest terms in the selected category |
||
65 | $resultA = $xoopsDB -> query( "SELECT entryID, categoryID, term, definition, uid, datesub, counter, html, smiley, xcodes, breaks, comments |
||
66 | FROM " . $xoopsDB -> prefix( "lxentries" ) . " |
||
67 | WHERE categoryID = " . $options[0] . " AND submit = '0' AND offline = 0 AND block= 1 |
||
68 | ORDER BY datesub DESC", |
||
69 | //ORDER BY " . $options[7] . " DESC ", |
||
70 | 1, 0 |
||
71 | ); |
||
72 | |||
73 | list( $entryID, $categoryID, $term, $definition, $authorID, $datesub, $counter, $html, $smiley, $xcodes, $breaks, $comments) = $xoopsDB->fetchRow($resultA); |
||
74 | $eID = intval($entryID); |
||
75 | // If there's no result - which means there's no definition yet... |
||
76 | if ($eID == 0) { |
||
77 | $block['display'] = 0; |
||
78 | } else { |
||
79 | $block['display'] = 1; |
||
80 | } |
||
81 | |||
82 | // Retrieve the category name |
||
83 | $resultB = $xoopsDB -> query( "SELECT name, logourl FROM ". $xoopsDB -> prefix( "lxcategories" ) . " WHERE categoryID = " . $options[0] . " " ); |
||
84 | list ( $name, $logourl ) = $xoopsDB -> fetchRow( $resultB ); |
||
85 | if ($lexikon =& $module_handler->getByDirname('lexikon')){ |
||
86 | if ( $gperm_handler -> checkRight( 'lexikon_view', $options[0], $groups, $module_id ) ){ |
||
87 | // get the items |
||
88 | $block['userID'] = (intval( $authorID )); |
||
89 | $block['authorname'] = XoopsUserUtility::getUnameFromId(intval( $authorID )); |
||
90 | $block['name'] = xoops_substr($name , 0, intval($options[9]) ) ; |
||
91 | $block['catID'] = intval ( $options[0] ); |
||
92 | $block['catimage'] = stripslashes($logourl); |
||
93 | $block['termID'] = intval ( $entryID ); |
||
94 | $block['title'] = $myts -> htmlSpecialChars( $term ); |
||
95 | $block['introtext'] = xoops_substr( $myts -> displayTarea( $definition, $html, 1, $xcodes, 1 ,$breaks), 0, intval($options[8]) ); |
||
96 | |||
97 | $block['moduledir'] = $lexikon->dirname(); |
||
98 | $block['date'] = formatTimestamp( $datesub, 'd M Y' ); |
||
99 | //$block['date'] = formatTimestamp( $datesub, $lxConfig['dateformat'] ); |
||
100 | $block['hits'] = intval( $counter ); |
||
101 | if (($lxConfig['com_rule'] != 0) || (($lxConfig['com_rule'] != 0) && is_object($xoopsUser))) { |
||
102 | if ($comments != 0) { |
||
103 | $block['comments'] = "<a href='".XOOPS_URL."/modules/" .$lexikon->dirname(). "/entry.php?entryID=".$block['termID']."'>"._COMMENTS." : ".$comments."</a>"; |
||
104 | } else { |
||
105 | $block['comments'] = "<a href='".XOOPS_URL."/modules/" .$lexikon->dirname(). "/entry.php?entryID=".$block['termID']."'>"._COMMENTS."?</a>"; |
||
106 | } |
||
107 | } |
||
108 | |||
109 | // get the other terms |
||
110 | $resultC = $xoopsDB -> query( "SELECT entryID, term, datesub FROM " . $xoopsDB -> prefix( "lxentries" ) . " WHERE categoryID = " . $options[0] . " AND entryID != ". $block['termID'] . " AND submit = 0 AND offline = 0 AND block= 1 ORDER BY " . $options[7] . " DESC ", $options[1], 0 ); |
||
111 | |||
112 | $i = 0; |
||
113 | while ( $myrow = $xoopsDB -> fetchArray ( $resultC )){ |
||
114 | if ( $i < $options[1]){ |
||
115 | $morelinks = array(); |
||
116 | $morelinks['id'] = $myrow['entryID']; |
||
117 | $morelinks['head'] = xoops_substr($myts -> htmlSpecialChars($myrow['term']) , 0, intval($options[9]) ) ; |
||
118 | |||
119 | $morelinks['subdate'] = formatTimestamp( $datesub, 'd M Y' ); |
||
120 | //$morelinks['subdate'] = formatTimestamp( $datesub, $lxConfig['dateformat'] ); |
||
121 | $i++; |
||
122 | $block['links'][] = $morelinks; |
||
123 | } |
||
124 | } |
||
125 | } else { // if permissions are not granted |
||
126 | $block['display'] = 0; |
||
127 | } |
||
128 | } |
||
129 | |||
130 | //------------ |
||
131 | |||
132 | return $block; |
||
133 | } |
||
134 | |||
185 |
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.