| Conditions | 9 |
| Paths | 80 |
| Total Lines | 52 |
| 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 |
||
| 35 | private function buildOptions() |
||
| 36 | { |
||
| 37 | |||
| 38 | if ((boolean) $this->getOption('show_empty')) { |
||
| 39 | $this->addValueOption(-1, ' '); |
||
| 40 | } |
||
| 41 | |||
| 42 | if ((boolean) $this->getOption('show_every')) { |
||
| 43 | $this->addValueOption(-2, 'Everybody'); |
||
| 44 | } |
||
| 45 | |||
| 46 | // Forge request to select users |
||
| 47 | $sql = "SELECT DISTINCT u.rowid, u.lastname as lastname, u.firstname, u.statut, u.login, u.admin, u.entity"; |
||
| 48 | $sql .= " FROM " . MAIN_DB_PREFIX . "user as u"; |
||
| 49 | $sql .= " WHERE u.entity IN (0,1)"; |
||
| 50 | if (!empty($this->getOption('USER_HIDE_INACTIVE_IN_COMBOBOX'))) { |
||
| 51 | $sql .= " AND u.statut <> 0"; |
||
| 52 | } |
||
| 53 | |||
| 54 | if (empty($this->getOption('MAIN_FIRSTNAME_NAME_POSITION'))) { |
||
| 55 | $sql .= " ORDER BY u.firstname ASC"; |
||
| 56 | } else { |
||
| 57 | $sql .= " ORDER BY u.lastname ASC"; |
||
| 58 | } |
||
| 59 | |||
| 60 | $resql = $this->db->query($sql); |
||
| 61 | if ($resql) { |
||
| 62 | $num = $this->db->num_rows($resql); |
||
| 63 | $i = 0; |
||
| 64 | if ($num) { |
||
| 65 | $userstatic = new User($this->db); |
||
| 66 | |||
| 67 | while ($i < $num) { |
||
| 68 | $obj = $this->db->fetch_object($resql); |
||
| 69 | |||
| 70 | $userstatic->id = $obj->rowid; |
||
| 71 | $userstatic->lastname = $obj->lastname; |
||
| 72 | $userstatic->firstname = $obj->firstname; |
||
| 73 | |||
| 74 | $fullNameMode = 0; //Lastname + firstname |
||
| 75 | if (empty($this->getOption('MAIN_FIRSTNAME_NAME_POSITION'))) { |
||
| 76 | $fullNameMode = 1; //firstname + lastname |
||
| 77 | } |
||
| 78 | |||
| 79 | $this->addValueOption($obj->rowid, $userstatic->getFullName(null, $fullNameMode)); |
||
| 80 | $i++; |
||
| 81 | } |
||
| 82 | } |
||
| 83 | |||
| 84 | |||
| 85 | } |
||
| 86 | } |
||
| 87 | } |