| Conditions | 8 |
| Paths | 10 |
| Total Lines | 61 |
| Code Lines | 43 |
| 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 |
||
| 25 | function b_sitemap_oledrion() |
||
| 26 | { |
||
| 27 | require_once dirname(__DIR__) . '/oledrion/header.php'; |
||
| 28 | global $sitemap_configs; |
||
| 29 | $xoopsDB = \XoopsDatabaseFactory::getDatabaseConnection(); |
||
| 30 | $table = $xoopsDB->prefix('oledrion_cat'); |
||
| 31 | $id_name = 'cat_cid'; |
||
| 32 | $pid_name = 'cat_pid'; |
||
| 33 | $title_name = 'cat_title'; |
||
| 34 | $url = 'category.php?cat_cid='; |
||
| 35 | $order = 'cat_title'; |
||
| 36 | |||
| 37 | require_once XOOPS_ROOT_PATH . '/class/xoopstree.php'; |
||
| 38 | $mytree = new \XoopsTree($table, $id_name, $pid_name); |
||
| 39 | $xoopsDB = \XoopsDatabaseFactory::getDatabaseConnection(); |
||
| 40 | |||
| 41 | $sitemap = []; |
||
| 42 | $myts = \MyTextSanitizer::getInstance(); |
||
| 43 | |||
| 44 | $i = 0; |
||
| 45 | $sql = "SELECT `$id_name`,`$title_name` FROM `$table` WHERE `$pid_name`=0"; |
||
| 46 | if ('' !== $order) { |
||
|
|
|||
| 47 | $sql .= " ORDER BY `$order`"; |
||
| 48 | } |
||
| 49 | $result = $xoopsDB->query($sql); |
||
| 50 | while (list($catid, $name) = $xoopsDB->fetchRow($result)) { |
||
| 51 | $sitemap['parent'][$i]['id'] = $catid; |
||
| 52 | $sitemap['parent'][$i]['title'] = $myts->htmlSpecialChars($name); |
||
| 53 | if (1 == Oledrion\Utility::getModuleOption('urlrewriting')) { |
||
| 54 | // On utilise l'url rewriting |
||
| 55 | $url = 'category' . '-' . (int)$catid . Oledrion\Utility::makeSeoUrl($name) . '.html'; |
||
| 56 | } else { |
||
| 57 | // Pas d'utilisation de l'url rewriting |
||
| 58 | $url = 'category.php?cat_cid=' . (int)$catid; |
||
| 59 | } |
||
| 60 | $sitemap['parent'][$i]['url'] = $url; |
||
| 61 | |||
| 62 | if (@$sitemap_configs['show_subcategoris']) { |
||
| 63 | $j = 0; |
||
| 64 | $child_ary = $mytree->getChildTreeArray($catid, $order); |
||
| 65 | foreach ($child_ary as $child) { |
||
| 66 | $count = mb_strlen($child['prefix']) + 1; |
||
| 67 | $sitemap['parent'][$i]['child'][$j]['id'] = $child[$id_name]; |
||
| 68 | $sitemap['parent'][$i]['child'][$j]['title'] = $myts->htmlSpecialChars($child[$title_name]); |
||
| 69 | $sitemap['parent'][$i]['child'][$j]['image'] = (($count > 3) ? 4 : $count); |
||
| 70 | if (1 == Oledrion\Utility::getModuleOption('urlrewriting')) { |
||
| 71 | // On utilise l'url rewriting |
||
| 72 | $url = 'category' . '-' . (int)$child[$id_name] . Oledrion\Utility::makeSeoUrl($child[$title_name]) . '.html'; |
||
| 73 | } else { |
||
| 74 | // Pas d'utilisation de l'url rewriting |
||
| 75 | $url = 'category.php?cat_cid=' . (int)$child[$id_name]; |
||
| 76 | } |
||
| 77 | $sitemap['parent'][$i]['child'][$j]['url'] = $url; |
||
| 78 | |||
| 79 | ++$j; |
||
| 80 | } |
||
| 81 | } |
||
| 82 | ++$i; |
||
| 83 | } |
||
| 84 | |||
| 85 | return $sitemap; |
||
| 86 | } |
||
| 87 |