| Conditions | 5 |
| Paths | 2 |
| Total Lines | 54 |
| 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 |
||
| 52 | protected function rebuildTree($idParent = 0, $left = 1, $depth = 0) |
||
| 53 | { |
||
| 54 | ini_set('xdebug.max_nesting_level', 10000); |
||
| 55 | ini_set('memory_limit', '-1'); |
||
| 56 | |||
| 57 | if ($result = $this->qb |
||
| 58 | ->table($this->table) |
||
| 59 | ->select('id') |
||
| 60 | ->where('id_parent', $idParent) |
||
| 61 | ->orderBy('id') |
||
| 62 | ->get()) { |
||
| 63 | |||
| 64 | $right = $left + 1; |
||
| 65 | |||
| 66 | $i = 0; |
||
| 67 | foreach ($result as $row) { |
||
| 68 | if ($i == 0) { |
||
| 69 | $this->qb |
||
| 70 | ->from($this->table) |
||
| 71 | ->where('id', $row->id) |
||
| 72 | ->update($update = [ |
||
| 73 | 'record_left' => $left, |
||
| 74 | 'record_right' => $right, |
||
| 75 | 'record_depth' => $depth, |
||
| 76 | ]); |
||
| 77 | } else { |
||
| 78 | $this->qb |
||
| 79 | ->from($this->table) |
||
| 80 | ->where('id', $row->id) |
||
| 81 | ->update($update = [ |
||
| 82 | 'record_left' => $left = $right + 1, |
||
| 83 | 'record_right' => $right = $left + 1, |
||
| 84 | 'record_depth' => $depth, |
||
| 85 | ]); |
||
| 86 | } |
||
| 87 | |||
| 88 | $update[ 'id' ] = $row->id; |
||
| 89 | |||
| 90 | if ($this->hasChilds($row->id)) { |
||
| 91 | $right = $this->rebuildTree($row->id, $right, $depth + 1); |
||
| 92 | $this->qb |
||
| 93 | ->from($this->table) |
||
| 94 | ->where('id', $row->id) |
||
| 95 | ->update($update = [ |
||
| 96 | 'record_right' => $right, |
||
| 97 | ]); |
||
| 98 | $update[ 'id' ] = $row->id; |
||
| 99 | } |
||
| 100 | |||
| 101 | $i++; |
||
| 102 | } |
||
| 103 | } |
||
| 104 | |||
| 105 | return $right + 1; |
||
|
|
|||
| 106 | } |
||
| 234 | } |