| Conditions | 13 | 
| Paths | 128 | 
| Total Lines | 66 | 
| Code Lines | 49 | 
| Lines | 10 | 
| Ratio | 15.15 % | 
| 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  | 
            ||
| 21 | function oledrion_search($queryarray, $andor, $limit, $offset, $userid)  | 
            ||
| 22 | { | 
            ||
| 23 | global $xoopsDB;  | 
            ||
| 
                                                                                                    
                        
                         | 
                |||
| 24 | require XOOPS_ROOT_PATH . '/modules/oledrion/include/common.php';  | 
            ||
| 25 | require_once XOOPS_ROOT_PATH . '/modules/oledrion/class/oledrion_products.php';  | 
            ||
| 26 | |||
| 27 | // Recherche dans les produits  | 
            ||
| 28 |     $sql = 'SELECT product_id, product_title, product_submitted, product_submitter FROM ' . $xoopsDB->prefix('oledrion_products') . ' WHERE (product_online = 1'; | 
            ||
| 29 |     if (oledrion_utils::getModuleOption('show_unpublished') == 0) { // Ne pas afficher les produits qui ne sont pas publiés | 
            ||
| 30 | $sql .= ' AND product_submitted <= ' . time();  | 
            ||
| 31 | }  | 
            ||
| 32 |     if (oledrion_utils::getModuleOption('nostock_display') == 0) { // Se limiter aux seuls produits encore en stock | 
            ||
| 33 | $sql .= ' AND product_stock > 0';  | 
            ||
| 34 | }  | 
            ||
| 35 |     if ($userid != 0) { | 
            ||
| 36 | $sql .= ' AND product_submitter = ' . $userid;  | 
            ||
| 37 | }  | 
            ||
| 38 | $sql .= ') ';  | 
            ||
| 39 | |||
| 40 | $tmpObject = new oledrion_products();  | 
            ||
| 41 | $datas = $tmpObject->getVars();  | 
            ||
| 42 | $tblFields = array();  | 
            ||
| 43 | $cnt = 0;  | 
            ||
| 44 | View Code Duplication |     foreach ($datas as $key => $value) { | 
            |
| 45 |         if ($value['data_type'] == XOBJ_DTYPE_TXTBOX || $value['data_type'] == XOBJ_DTYPE_TXTAREA) { | 
            ||
| 46 |             if ($cnt == 0) { | 
            ||
| 47 | $tblFields[] = $key;  | 
            ||
| 48 |             } else { | 
            ||
| 49 | $tblFields[] = ' OR ' . $key;  | 
            ||
| 50 | }  | 
            ||
| 51 | $cnt++;  | 
            ||
| 52 | }  | 
            ||
| 53 | }  | 
            ||
| 54 | |||
| 55 | $count = count($queryarray);  | 
            ||
| 56 | $more = '';  | 
            ||
| 57 |     if (is_array($queryarray) && $count > 0) { | 
            ||
| 58 | $cnt = 0;  | 
            ||
| 59 |         $sql .= ' AND ('; | 
            ||
| 60 | $more = ')';  | 
            ||
| 61 |         foreach ($queryarray as $oneQuery) { | 
            ||
| 62 |             $sql .= '('; | 
            ||
| 63 | $cond = " LIKE '%" . $oneQuery . "%' ";  | 
            ||
| 64 | $sql .= implode($cond, $tblFields) . $cond . ')';  | 
            ||
| 65 | $cnt++;  | 
            ||
| 66 |             if ($cnt != $count) { | 
            ||
| 67 | $sql .= ' ' . $andor . ' ';  | 
            ||
| 68 | }  | 
            ||
| 69 | }  | 
            ||
| 70 | }  | 
            ||
| 71 | $sql .= $more . ' ORDER BY product_submitted DESC';  | 
            ||
| 72 | $i = 0;  | 
            ||
| 73 | $ret = array();  | 
            ||
| 74 | $myts = MyTextSanitizer::getInstance();  | 
            ||
| 75 | $result = $xoopsDB->query($sql, $limit, $offset);  | 
            ||
| 76 |     while ($myrow = $xoopsDB->fetchArray($result)) { | 
            ||
| 77 | $ret[$i]['image'] = 'assets/images/product.png';  | 
            ||
| 78 | $ret[$i]['link'] = "product.php?product_id=" . $myrow['product_id'];  | 
            ||
| 79 | $ret[$i]['title'] = $myts->htmlSpecialChars($myrow['product_title']);  | 
            ||
| 80 | $ret[$i]['time'] = $myrow['product_submitted'];  | 
            ||
| 81 | $ret[$i]['uid'] = $myrow['product_submitter'];  | 
            ||
| 82 | $i++;  | 
            ||
| 83 | }  | 
            ||
| 84 | |||
| 85 | return $ret;  | 
            ||
| 86 | }  | 
            ||
| 87 | 
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