| Conditions | 9 |
| Paths | 40 |
| Total Lines | 57 |
| Code Lines | 23 |
| 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 |
||
| 37 | public function select() |
||
| 38 | { |
||
| 39 | global $babDB; |
||
| 40 | |||
| 41 | $res = $babDB->db_query("SELECT ee.id_entry, ee.id, ee.quantity, e.date_begin, e.date_end, e.id_user, r.quantity_unit FROM |
||
| 42 | absences_entries e, |
||
| 43 | absences_entries_elem ee, |
||
| 44 | absences_rights r, |
||
| 45 | absences_types t |
||
| 46 | WHERE |
||
| 47 | ee.id_entry = e.id |
||
| 48 | AND ee.date_begin = '0000-00-00 00:00:00' |
||
| 49 | AND r.id = ee.id_right |
||
| 50 | AND t.id = r.id_type |
||
| 51 | ORDER BY e.id, r.sortkey, t.name |
||
| 52 | "); |
||
| 53 | |||
| 54 | $this->totalCount = $babDB->db_num_rows($res); |
||
| 55 | |||
| 56 | if ($this->totalCount > 0) { |
||
| 57 | $this->progress = new bab_installProgressBar; |
||
| 58 | $this->progress->setTitle(sprintf(absences_translate('Update existing vacation requests (%d)'), $this->totalCount)); |
||
| 59 | } |
||
| 60 | |||
| 61 | $entry_stack = array(); |
||
| 62 | while ($entry_elem = $babDB->db_fetch_assoc($res)) { |
||
| 63 | |||
| 64 | $id_entry = (int) $entry_elem['id_entry']; |
||
| 65 | |||
| 66 | if ('0000-00-00 00:00:00' === $entry_elem['date_begin'] || '0000-00-00 00:00:00' === $entry_elem['date_end']) { |
||
| 67 | absences_Entry::getById($entry_elem['id_entry'])->delete(); |
||
| 68 | continue; |
||
| 69 | } |
||
| 70 | |||
| 71 | if (!isset($entry_stack[$id_entry])) { |
||
| 72 | |||
| 73 | if (!empty($entry_stack)) { |
||
| 74 | // process previous stack |
||
| 75 | $this->updateEntry(reset($entry_stack)); |
||
| 76 | $entry_stack = array(); |
||
| 77 | } |
||
| 78 | |||
| 79 | $entry_stack[$id_entry] = array(); |
||
| 80 | } |
||
| 81 | |||
| 82 | $entry_stack[$id_entry][] = $entry_elem; |
||
| 83 | } |
||
| 84 | |||
| 85 | // process last stack entry if exists |
||
| 86 | if ($entry_stack) { |
||
|
|
|||
| 87 | $this->updateEntry(reset($entry_stack)); |
||
| 88 | } |
||
| 89 | |||
| 90 | if (isset($this->progress)) { |
||
| 91 | $this->progress->setProgression(100); |
||
| 92 | } |
||
| 93 | } |
||
| 94 | |||
| 154 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.