| Conditions | 19 |
| Paths | 194 |
| Total Lines | 89 |
| Code Lines | 47 |
| 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 |
||
| 42 | } |
||
| 43 | /** @var \XoopsModuleHandler $moduleHandler */ |
||
| 44 | $moduleHandler = xoops_getHandler('module'); |
||
| 45 | $tdmModule = $moduleHandler->getByDirname($dirname); |
||
| 46 | $groups = is_object($xoopsUser) ? $xoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS; |
||
| 47 | |||
| 48 | /** @var \XoopsGroupPermHandler $grouppermHandler */ |
||
| 49 | $grouppermHandler = xoops_getHandler('groupperm'); |
||
| 50 | $categories = $grouppermHandler->getItemIds($permtype, $groups, $tdmModule->getVar('mid')); |
||
| 51 | |||
| 52 | return $categories; |
||
| 53 | } |
||
| 54 | |||
| 55 | /** |
||
| 56 | * retourne le nombre de téléchargements dans le catégories enfants d'une catégorie |
||
| 57 | * @param \XoopsModules\Tdmdownloads\Tree $mytree |
||
| 58 | * @param $categories |
||
| 59 | * @param $entries |
||
| 60 | * @param $cid |
||
| 61 | * @return int |
||
| 62 | */ |
||
| 63 | public function getNumbersOfEntries($mytree, $categories, $entries, $cid) |
||
| 64 | { |
||
| 65 | $count = 0; |
||
| 66 | $child_arr = []; |
||
|
|
|||
| 67 | if (in_array($cid, $categories, true)) { |
||
| 68 | $child = $mytree->getAllChild($cid); |
||
| 69 | foreach (array_keys($entries) as $i) { |
||
| 70 | /** @var \XoopsModules\Tdmdownloads\Downloads[] $entries */ |
||
| 71 | if ($entries[$i]->getVar('cid') == $cid) { |
||
| 72 | $count++; |
||
| 73 | } |
||
| 74 | foreach (array_keys($child) as $j) { |
||
| 75 | if ($entries[$i]->getVar('cid') == $j) { |
||
| 76 | $count++; |
||
| 77 | } |
||
| 78 | } |
||
| 79 | } |
||
| 80 | } |
||
| 81 | |||
| 82 | return $count; |
||
| 83 | } |
||
| 84 | |||
| 85 | /** |
||
| 86 | * retourne une image "nouveau" ou "mise à jour" |
||
| 87 | * @param $time |
||
| 88 | * @param $status |
||
| 89 | * @return string |
||
| 90 | */ |
||
| 91 | public function getStatusImage($time, $status) |
||
| 92 | { |
||
| 93 | global $xoopsModuleConfig; |
||
| 94 | $count = 7; |
||
| 95 | $new = ''; |
||
| 96 | $startdate = (time() - (86400 * $count)); |
||
| 97 | if (1 == $xoopsModuleConfig['showupdated']) { |
||
| 98 | if ($startdate < $time) { |
||
| 99 | $language = $GLOBALS['xoopsConfig']['language']; |
||
| 100 | if (!is_dir(XOOPS_ROOT_PATH . '/modules/tdmdownloads/language/' . $language . '/')) { |
||
| 101 | $language = 'english'; |
||
| 102 | } |
||
| 103 | $img_path = XOOPS_ROOT_PATH . '/modules/tdmdownloads/language/' . $language . '/'; |
||
| 104 | $img_url = XOOPS_URL . '/modules/tdmdownloads/language/' . $language . '/'; |
||
| 105 | if (1 == $status) { |
||
| 106 | if (is_readable($img_path . 'new.png')) { |
||
| 107 | $new = ' <img src="' . $img_url . 'new.png" alt="' . _MD_TDMDOWNLOADS_INDEX_NEWTHISWEEK . '" title="' . _MD_TDMDOWNLOADS_INDEX_NEWTHISWEEK . '">'; |
||
| 108 | } else { |
||
| 109 | $new = ' <img src="' . XOOPS_URL . '/modules/tdmdownloads/language/english/new.png" alt="' . _MD_TDMDOWNLOADS_INDEX_NEWTHISWEEK . '" title="' . _MD_TDMDOWNLOADS_INDEX_NEWTHISWEEK . '">'; |
||
| 110 | } |
||
| 111 | } elseif (2 == $status) { |
||
| 112 | if (is_readable($img_path . 'updated.png')) { |
||
| 113 | $new = ' <img src="' . $img_url . 'updated.png" alt="' . _MD_TDMDOWNLOADS_INDEX_UPTHISWEEK . '" title="' . _MD_TDMDOWNLOADS_INDEX_UPTHISWEEK . '">'; |
||
| 114 | } else { |
||
| 115 | $new = ' <img src="' . XOOPS_URL . '/modules/tdmdownloads/language/english/updated.png" alt="' . _MD_TDMDOWNLOADS_INDEX_UPTHISWEEK . '" title="' . _MD_TDMDOWNLOADS_INDEX_UPTHISWEEK . '">'; |
||
| 116 | } |
||
| 117 | } |
||
| 118 | } |
||
| 119 | } |
||
| 120 | |||
| 121 | return $new; |
||
| 122 | } |
||
| 123 | |||
| 124 | /** |
||
| 125 | * retourne une image "populaire" |
||
| 126 | * @param $hits |
||
| 127 | * @return string |
||
| 128 | */ |
||
| 129 | public function getPopularImage($hits) |
||
| 130 | { |
||
| 131 | global $xoopsModuleConfig; |
||
| 239 |