Conditions | 13 |
Paths | 190 |
Total Lines | 92 |
Code Lines | 72 |
Lines | 0 |
Ratio | 0 % |
Changes | 3 | ||
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 |
||
17 | function b_tdmdownloads_top_show($options) |
||
18 | { |
||
19 | require_once XOOPS_ROOT_PATH."/modules/TDMDownloads/include/functions.php"; |
||
20 | //appel de la class |
||
21 | $downloads_Handler =& xoops_getModuleHandler('tdmdownloads_downloads', 'TDMDownloads'); |
||
22 | $block = array(); |
||
23 | $type_block = $options[0]; |
||
24 | $nb_entree = $options[1]; |
||
25 | $lenght_title = $options[2]; |
||
26 | $use_logo = $options[3]; |
||
27 | $use_description = $options[4]; |
||
28 | $show_inforation = $options[5]; |
||
29 | $logo_float = $options[6]; |
||
30 | $logo_white = $options[7]; |
||
31 | |||
32 | array_shift($options); |
||
33 | array_shift($options); |
||
34 | array_shift($options); |
||
35 | array_shift($options); |
||
36 | array_shift($options); |
||
37 | array_shift($options); |
||
38 | array_shift($options); |
||
39 | array_shift($options); |
||
40 | |||
41 | // Add styles |
||
42 | global $xoTheme; |
||
|
|||
43 | $xoTheme->addStylesheet(XOOPS_URL . '/modules/TDMDownloads/css/blocks.css', null); |
||
44 | |||
45 | $categories = TDMDownloads_MygetItemIds('tdmdownloads_view', 'TDMDownloads'); |
||
46 | $criteria = new CriteriaCompo(); |
||
47 | $criteria->add(new Criteria('cid', '(' . implode(',', $categories) . ')','IN')); |
||
48 | if (!(count($options) == 1 && $options[0] == 0)) { |
||
49 | $criteria->add(new Criteria('cid', '(' . implode(',', $options) . ')','IN')); |
||
50 | } |
||
51 | $criteria->add(new Criteria('status', 0, '!=')); |
||
52 | switch ($type_block) { // pour le bloc: dernier fichier |
||
53 | case "date": |
||
54 | $criteria->setSort('date'); |
||
55 | $criteria->setOrder('DESC'); |
||
56 | break; |
||
57 | // pour le bloc: plus t�l�charg� |
||
58 | case "hits": |
||
59 | $criteria->setSort('hits'); |
||
60 | $criteria->setOrder('DESC'); |
||
61 | break; |
||
62 | // pour le bloc: mieux not� |
||
63 | case "rating": |
||
64 | $criteria->setSort('rating'); |
||
65 | $criteria->setOrder('DESC'); |
||
66 | break; |
||
67 | // pour le bloc: al�atoire |
||
68 | case "random": |
||
69 | $criteria->setSort('RAND()'); |
||
70 | break; |
||
71 | } |
||
72 | $criteria->setLimit($nb_entree); |
||
73 | $downloads_arr = $downloads_Handler->getall($criteria); |
||
74 | foreach (array_keys($downloads_arr) as $i) { |
||
75 | $block[$i]['lid'] = $downloads_arr[$i]->getVar('lid'); |
||
76 | $block[$i]['title'] = strlen($downloads_arr[$i]->getVar('title')) > $lenght_title ? substr($downloads_arr[$i]->getVar('title'),0,($lenght_title))."..." : $downloads_arr[$i]->getVar('title'); |
||
77 | $description_short = ''; |
||
78 | if ($use_description == true) { |
||
79 | $description = $downloads_arr[$i]->getVar('description'); |
||
80 | //permet d'afficher uniquement la description courte |
||
81 | if (strpos($description,'[pagebreak]')==false) { |
||
82 | $description_short = mb_substr($description,0,400,'utf-8') . ' ...'; |
||
83 | } else { |
||
84 | $description_short = mb_substr($description,0,strpos($description,'[pagebreak]'),'utf-8') . ' ...'; |
||
85 | } |
||
86 | } |
||
87 | $block[$i]['description'] = $description_short; |
||
88 | $logourl = ''; |
||
89 | if ($use_logo == true) { |
||
90 | if ($downloads_arr[$i]->getVar('logourl') == 'blank.gif') { |
||
91 | $logourl = ''; |
||
92 | } else { |
||
93 | $logourl = XOOPS_URL . '/uploads/TDMDownloads/images/shots/'. $downloads_arr[$i]->getVar('logourl'); |
||
94 | } |
||
95 | } |
||
96 | $block[$i]['logourl'] = $logourl; |
||
97 | $block[$i]['logourl_class'] = $logo_float; |
||
98 | $block[$i]['logourl_width'] = $logo_white; |
||
99 | $block[$i]['hits'] = $downloads_arr[$i]->getVar("hits"); |
||
100 | $block[$i]['rating'] = number_format($downloads_arr[$i]->getVar("rating"),1); |
||
101 | $block[$i]['date'] = formatTimeStamp($downloads_arr[$i]->getVar("date"),"s"); |
||
102 | $block[$i]['submitter'] = XoopsUser::getUnameFromId($downloads_arr[$i]->getVar('submitter')); |
||
103 | $block[$i]['inforation'] = $show_inforation; |
||
104 | |||
105 | } |
||
106 | |||
107 | return $block; |
||
108 | } |
||
109 | |||
172 |
Instead of relying on
global
state, we recommend one of these alternatives:1. Pass all data via parameters
2. Create a class that maintains your state