| Conditions | 13 |
| Paths | 8 |
| Total Lines | 34 |
| Code Lines | 22 |
| 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 |
||
| 73 | public function all($withPrivilege = true) { |
||
| 74 | $roles_id = ($withPrivilege)?cb()->session()->roleId():null; |
||
| 75 | $menus = $this->loadData(); |
||
| 76 | $result = []; |
||
| 77 | foreach($menus as $menu) { |
||
| 78 | |||
| 79 | if($withPrivilege && !$this->checkPrivilege($roles_id, $menu)) continue; |
||
| 80 | |||
| 81 | $sidebarModel = $this->assignToModel($menu); |
||
| 82 | if($menus2 = $this->loadData($menu->id)) { |
||
| 83 | $sub1 = []; |
||
| 84 | foreach ($menus2 as $menu2) { |
||
| 85 | |||
| 86 | if($withPrivilege && !$this->checkPrivilege($roles_id, $menu2)) continue; |
||
| 87 | |||
| 88 | $sidebarModel2 = $this->assignToModel($menu2); |
||
| 89 | if($menus3 = $this->loadData($menu2->id)) { |
||
| 90 | $sub2 = []; |
||
| 91 | foreach ($menus3 as $menu3) { |
||
| 92 | |||
| 93 | if($withPrivilege && !$this->checkPrivilege($roles_id, $menu3)) continue; |
||
| 94 | |||
| 95 | $sidebarModel3 = $this->assignToModel($menu3); |
||
| 96 | $sub2[] = $sidebarModel3; |
||
| 97 | } |
||
| 98 | $sidebarModel2->setSub($sub2); |
||
| 99 | } |
||
| 100 | $sub1[] = $sidebarModel2; |
||
| 101 | } |
||
| 102 | $sidebarModel->setSub($sub1); |
||
| 103 | } |
||
| 104 | $result[] = $sidebarModel; |
||
| 105 | } |
||
| 106 | return $result; |
||
| 107 | } |
||
| 109 | } |