| Conditions | 10 |
| Paths | 4 |
| Total Lines | 67 |
| Code Lines | 37 |
| 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:
Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.
There are several approaches to avoid long parameter lists:
| 1 | <?php |
||
| 61 | function select_journal($selectid, $htmlname = 'journal', $nature=0, $showempty = 0, $event = array(), $select_in = 0, $select_out = 0, $morecss='maxwidth300 maxwidthonsmartphone', $usecache='') |
||
| 62 | { |
||
| 63 | global $conf; |
||
| 64 | |||
| 65 | $out = ''; |
||
| 66 | |||
| 67 | $options = array(); |
||
| 68 | if ($usecache && ! empty($this->options_cache[$usecache])) |
||
| 69 | { |
||
| 70 | $options = $this->options_cache[$usecache]; |
||
| 71 | $selected=$selectid; |
||
| 72 | } |
||
| 73 | else |
||
| 74 | { |
||
| 75 | $sql = "SELECT rowid, code, label, nature, entity, active"; |
||
| 76 | $sql.= " FROM " . MAIN_DB_PREFIX . "accounting_journal"; |
||
| 77 | $sql.= " WHERE active = 1"; |
||
| 78 | $sql.= " AND entity = ".$conf->entity; |
||
| 79 | //if ($nature && is_numeric($nature)) $sql .= " AND nature = ".$nature; |
||
| 80 | $sql.= " ORDER BY code"; |
||
| 81 | |||
| 82 | dol_syslog(get_class($this) . "::select_journal", LOG_DEBUG); |
||
| 83 | $resql = $this->db->query($sql); |
||
| 84 | |||
| 85 | if (!$resql) { |
||
| 86 | $this->error = "Error ".$this->db->lasterror(); |
||
| 87 | dol_syslog(get_class($this)."::select_journal ".$this->error, LOG_ERR); |
||
| 88 | return -1; |
||
| 89 | } |
||
| 90 | |||
| 91 | $out = ajax_combobox($htmlname, $event); |
||
| 92 | |||
| 93 | $selected = 0; |
||
| 94 | while ($obj = $this->db->fetch_object($resql)) |
||
| 95 | { |
||
| 96 | $label = $obj->code . ' - ' . $obj->label; |
||
| 97 | |||
| 98 | $select_value_in = $obj->rowid; |
||
| 99 | $select_value_out = $obj->rowid; |
||
| 100 | |||
| 101 | // Try to guess if we have found default value |
||
| 102 | if ($select_in == 1) { |
||
| 103 | $select_value_in = $obj->code; |
||
| 104 | } |
||
| 105 | if ($select_out == 1) { |
||
| 106 | $select_value_out = $obj->code; |
||
| 107 | } |
||
| 108 | // Remember guy's we store in database llx_accounting_bookkeeping the code of accounting_journal and not the rowid |
||
| 109 | if ($selectid != '' && $selectid == $select_value_in) { |
||
| 110 | //var_dump("Found ".$selectid." ".$select_value_in); |
||
| 111 | $selected = $select_value_out; |
||
| 112 | } |
||
| 113 | |||
| 114 | $options[$select_value_out] = $label; |
||
| 115 | } |
||
| 116 | $this->db->free($resql); |
||
| 117 | |||
| 118 | if ($usecache) |
||
| 119 | { |
||
| 120 | $this->options_cache[$usecache] = $options; |
||
| 121 | } |
||
| 122 | } |
||
| 123 | |||
| 124 | $out .= Form::selectarray($htmlname, $options, $select, $showempty, 0, 0, '', 0, 0, 0, '', $morecss, 1); |
||
|
|
|||
| 125 | |||
| 126 | return $out; |
||
| 127 | } |
||
| 128 | |||
| 210 |
This check looks for variables that are accessed but have not been defined. It raises an issue if it finds another variable that has a similar name.
The variable may have been renamed without also renaming all references.