| Conditions | 8 | 
| Paths | 10 | 
| Total Lines | 58 | 
| Code Lines | 44 | 
| Lines | 0 | 
| Ratio | 0 % | 
| Changes | 2 | ||
| 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  | 
            ||
| 21 | function b_sitemap_oledrion()  | 
            ||
| 22 | { | 
            ||
| 23 | require '../oledrion/header.php';  | 
            ||
| 24 | global $sitemap_configs;  | 
            ||
| 
                                                                                                    
                        
                         | 
                |||
| 25 | $xoopsDB = XoopsDatabaseFactory::getDatabaseConnection();  | 
            ||
| 26 |     $table = $xoopsDB->prefix('oledrion_cat'); | 
            ||
| 27 | $id_name = 'cat_cid';  | 
            ||
| 28 | $pid_name = 'cat_pid';  | 
            ||
| 29 | $title_name = 'cat_title';  | 
            ||
| 30 | $url = 'category.php?cat_cid=';  | 
            ||
| 31 | $order = 'cat_title';  | 
            ||
| 32 | |||
| 33 | include_once XOOPS_ROOT_PATH . '/class/xoopstree.php';  | 
            ||
| 34 | $mytree = new XoopsTree($table, $id_name, $pid_name);  | 
            ||
| 35 | $xoopsDB = XoopsDatabaseFactory::getDatabaseConnection();  | 
            ||
| 36 | |||
| 37 | $sitemap = array();  | 
            ||
| 38 | $myts = MyTextSanitizer::getInstance();  | 
            ||
| 39 | |||
| 40 | $i = 0;  | 
            ||
| 41 | $sql = "SELECT `$id_name`,`$title_name` FROM `$table` WHERE `$pid_name`=0";  | 
            ||
| 42 |     if ($order != '') { | 
            ||
| 43 | $sql .= " ORDER BY `$order`";  | 
            ||
| 44 | }  | 
            ||
| 45 | $result = $xoopsDB->query($sql);  | 
            ||
| 46 |     while (list($catid, $name) = $xoopsDB->fetchRow($result)) { | 
            ||
| 47 | $sitemap['parent'][$i]['id'] = $catid;  | 
            ||
| 48 | $sitemap['parent'][$i]['title'] = $myts->htmlSpecialChars($name);  | 
            ||
| 49 |         if (oledrion_utils::getModuleOption('urlrewriting') == 1) { // On utilise l'url rewriting | 
            ||
| 50 | $url = 'category' . '-' . intval($catid) . oledrion_utils::makeSeoUrl($name) . '.html';  | 
            ||
| 51 |         } else { // Pas d'utilisation de l'url rewriting | 
            ||
| 52 | $url = 'category.php?cat_cid=' . intval($catid);  | 
            ||
| 53 | }  | 
            ||
| 54 | $sitemap['parent'][$i]['url'] = $url;  | 
            ||
| 55 | |||
| 56 |         if (@$sitemap_configs["show_subcategoris"]) { | 
            ||
| 57 | $j = 0;  | 
            ||
| 58 | $child_ary = $mytree->getChildTreeArray($catid, $order);  | 
            ||
| 59 |             foreach ($child_ary as $child) { | 
            ||
| 60 | $count = strlen($child['prefix']) + 1;  | 
            ||
| 61 | $sitemap['parent'][$i]['child'][$j]['id'] = $child[$id_name];  | 
            ||
| 62 | $sitemap['parent'][$i]['child'][$j]['title'] = $myts->htmlSpecialChars($child[$title_name]);  | 
            ||
| 63 | $sitemap['parent'][$i]['child'][$j]['image'] = (($count > 3) ? 4 : $count);  | 
            ||
| 64 |                 if (oledrion_utils::getModuleOption('urlrewriting') == 1) { // On utilise l'url rewriting | 
            ||
| 65 | $url = 'category' . '-' . intval($child[$id_name]) . oledrion_utils::makeSeoUrl($child[$title_name]) . '.html';  | 
            ||
| 66 |                 } else { // Pas d'utilisation de l'url rewriting | 
            ||
| 67 | $url = 'category.php?cat_cid=' . intval($child[$id_name]);  | 
            ||
| 68 | }  | 
            ||
| 69 | $sitemap['parent'][$i]['child'][$j]['url'] = $url;  | 
            ||
| 70 | |||
| 71 | $j++;  | 
            ||
| 72 | }  | 
            ||
| 73 | }  | 
            ||
| 74 | $i++;  | 
            ||
| 75 | }  | 
            ||
| 76 | |||
| 77 | return $sitemap;  | 
            ||
| 78 | }  | 
            ||
| 79 | 
Instead of relying on
globalstate, we recommend one of these alternatives:1. Pass all data via parameters
2. Create a class that maintains your state