| Conditions | 12 |
| Paths | 12 |
| Total Lines | 55 |
| Code Lines | 38 |
| 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 |
||
| 60 | function exec_rechercher_args($id, $type, $exclus, $rac, $do) { |
||
|
|
|||
| 61 | if (!$do) { |
||
| 62 | $do = 'aff'; |
||
| 63 | } |
||
| 64 | |||
| 65 | $points = $rub = array(); |
||
| 66 | |||
| 67 | $where = preg_split(",\s+,", $type); |
||
| 68 | if ($where) { |
||
| 69 | foreach ($where as $k => $v) { |
||
| 70 | $where[$k] = "'%" . substr(str_replace("%", "\%", sql_quote($v, '', 'string')), 1, -1) . "%'"; |
||
| 71 | } |
||
| 72 | $where_titre = ("(titre LIKE " . join(" AND titre LIKE ", $where) . ")"); |
||
| 73 | $where_desc = ("(descriptif LIKE " . join(" AND descriptif LIKE ", $where) . ")"); |
||
| 74 | $where_id = ("(id_rubrique = " . intval($type) . ")"); |
||
| 75 | |||
| 76 | if ($exclus) { |
||
| 77 | include_spip('inc/rubriques'); |
||
| 78 | $where_exclus = " AND " . sql_in('id_rubrique', calcul_branche_in($exclus), 'NOT'); |
||
| 79 | } else { |
||
| 80 | $where_exclus = ''; |
||
| 81 | } |
||
| 82 | |||
| 83 | foreach (array( |
||
| 84 | 3 => $where_titre, |
||
| 85 | 2 => $where_desc, |
||
| 86 | 1 => $where_id, |
||
| 87 | ) as $point => $recherche) { |
||
| 88 | $res = sql_select("id_rubrique, id_parent, titre", "spip_rubriques", "$recherche$where_exclus"); |
||
| 89 | while ($row = sql_fetch($res)) { |
||
| 90 | $id_rubrique = $row["id_rubrique"]; |
||
| 91 | if (!isset($rub[$id_rubrique])) { |
||
| 92 | $rub[$id_rubrique] = array(); |
||
| 93 | } |
||
| 94 | $rub[$id_rubrique]["titre"] = typo($row["titre"]); |
||
| 95 | $rub[$id_rubrique]["id_parent"] = $row["id_parent"]; |
||
| 96 | if (!isset($points[$id_rubrique])) { |
||
| 97 | $points[$id_rubrique] = 0; |
||
| 98 | } |
||
| 99 | $points[$id_rubrique] = $points[$id_rubrique] + $point; |
||
| 100 | } |
||
| 101 | } |
||
| 102 | } |
||
| 103 | |||
| 104 | if ($points) { |
||
| 105 | arsort($points); |
||
| 106 | $style = " style='background-image: url(" . chemin_image('secteur-12.png') . ")'"; |
||
| 107 | foreach ($rub as $k => $v) { |
||
| 108 | $rub[$k]['atts'] = ($v["id_parent"] ? $style : '') |
||
| 109 | . " class='petite-rubrique'"; |
||
| 110 | } |
||
| 111 | } |
||
| 112 | |||
| 113 | return (proposer_item($points, $rub, $rac, $type, $do)); |
||
| 114 | } |
||
| 115 | |||
| 168 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.