| Conditions | 3 |
| Paths | 3 |
| Total Lines | 57 |
| Code Lines | 14 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| 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 |
||
| 125 | public function getNextValue($objsoc, $object) |
||
| 126 | { |
||
| 127 | global $db, $conf; |
||
| 128 | |||
| 129 | /* |
||
| 130 | // First, we get the max value |
||
| 131 | $posindice = strlen($this->prefix) + 6; |
||
| 132 | $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max"; |
||
| 133 | $sql .= " FROM ".MAIN_DB_PREFIX."adherent"; |
||
| 134 | $sql .= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'"; |
||
| 135 | $sql .= " AND entity = ".$conf->entity; |
||
| 136 | |||
| 137 | $resql = $db->query($sql); |
||
| 138 | if ($resql) { |
||
| 139 | $obj = $db->fetch_object($resql); |
||
| 140 | if ($obj) { |
||
| 141 | $max = intval($obj->max); |
||
| 142 | } else { |
||
| 143 | $max = 0; |
||
| 144 | } |
||
| 145 | } else { |
||
| 146 | dol_syslog("mod_member_simple::getNextValue", LOG_DEBUG); |
||
| 147 | return -1; |
||
| 148 | } |
||
| 149 | |||
| 150 | $date = empty($object->date_c) ? dol_now() : $object->date_c; |
||
| 151 | |||
| 152 | //$yymm = strftime("%y%m",time()); |
||
| 153 | $yymm = strftime("%y%m", $date); |
||
| 154 | |||
| 155 | if ($max >= (pow(10, 4) - 1)) { |
||
| 156 | $num = $max + 1; // If counter > 9999, we do not format on 4 chars, we take number as it is |
||
| 157 | } else { |
||
| 158 | $num = sprintf("%04s", $max + 1); |
||
| 159 | } |
||
| 160 | |||
| 161 | dol_syslog("mod_member_simple::getNextValue return ".$this->prefix.$yymm."-".$num); |
||
| 162 | return $this->prefix.$yymm."-".$num; |
||
| 163 | */ |
||
| 164 | |||
| 165 | // For the moment, the ref of a member is the rowid |
||
| 166 | $sql = "SELECT MAX(rowid) as max"; |
||
| 167 | $sql .= " FROM ".MAIN_DB_PREFIX."adherent"; |
||
| 168 | |||
| 169 | $resql = $db->query($sql); |
||
| 170 | if ($resql) { |
||
| 171 | $obj = $db->fetch_object($resql); |
||
| 172 | if ($obj) { |
||
| 173 | $max = intval($obj->max); |
||
| 174 | } else { |
||
| 175 | $max = 0; |
||
| 176 | } |
||
| 177 | } else { |
||
| 178 | dol_syslog("mod_member_simple::getNextValue", LOG_DEBUG); |
||
| 179 | return -1; |
||
| 180 | } |
||
| 181 | return ($max + 1); |
||
| 182 | } |
||
| 184 |