| Conditions | 4 |
| Paths | 2 |
| Total Lines | 85 |
| Code Lines | 58 |
| 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 |
||
| 73 | public function searchThroughAdminPages($term) |
||
| 74 | { |
||
| 75 | $adminPages = collect([ |
||
| 76 | [ |
||
| 77 | 'label' => 'Menu', |
||
| 78 | 'url' => route('chief.back.menus.index'), |
||
| 79 | 'permission' => 'update-page', |
||
| 80 | 'tags' => ['navigatie'], |
||
| 81 | ], [ |
||
| 82 | 'label' => 'Media', |
||
| 83 | 'url' => route('chief.mediagallery.index'), |
||
| 84 | 'permission' => 'update-page', |
||
| 85 | 'tags' => ['mediagalerij', 'mediabibliotheek', 'assets'], |
||
| 86 | ], [ |
||
| 87 | 'label' => 'Teksten', |
||
| 88 | 'url' => route('squanto.index'), |
||
| 89 | 'permission' => 'view-squanto', |
||
| 90 | 'tags' => ['squanto', 'mediagalerij', 'mediabibliotheek', 'assets'], |
||
| 91 | ], [ |
||
| 92 | 'label' => 'Sitemap', |
||
| 93 | 'url' => route('chief.back.sitemap.show'), |
||
| 94 | 'permission' => null, |
||
| 95 | 'tags' => [], |
||
| 96 | ], [ |
||
| 97 | 'label' => 'Admins', |
||
| 98 | 'url' => route('chief.back.users.index'), |
||
| 99 | 'permission' => 'view-user', |
||
| 100 | 'tags' => [], |
||
| 101 | ], [ |
||
| 102 | 'label' => 'Rechten', |
||
| 103 | 'url' => route('chief.back.roles.index'), |
||
| 104 | 'permission' => 'view-role', |
||
| 105 | 'tags' => ['roles'], |
||
| 106 | ], [ |
||
| 107 | 'label' => 'Settings', |
||
| 108 | 'url' => route('chief.back.settings.edit'), |
||
| 109 | 'permission' => 'update-setting', |
||
| 110 | 'tags' => ['instellingen'], |
||
| 111 | ], [ |
||
| 112 | 'label' => 'Audit', |
||
| 113 | 'url' => route('chief.back.audit.index'), |
||
| 114 | 'permission' => 'view-audit', |
||
| 115 | 'tags' => [], |
||
| 116 | ], [ |
||
| 117 | 'label' => chiefAdmin()->firstname, |
||
| 118 | 'url' => route('chief.back.you.edit'), |
||
| 119 | 'permission' => 'update-you', |
||
| 120 | 'tags' => ['account'], |
||
| 121 | ], [ |
||
| 122 | 'label' => 'Logout', |
||
| 123 | 'url' => route('chief.back.logout'), |
||
| 124 | 'permission' => null, |
||
| 125 | 'tags' => [], |
||
| 126 | ], |
||
| 127 | ]); |
||
| 128 | |||
| 129 | $models = $adminPages->filter(function ($adminPage) use ($term) { |
||
| 130 | // Check if label contains search term |
||
| 131 | if (Str::contains(Str::lower($adminPage['label']), $term)) { |
||
| 132 | return true; |
||
| 133 | } |
||
| 134 | |||
| 135 | // Check if any of tags contain search term |
||
| 136 | if (collect($adminPage['tags'])->contains(function ($tag) use ($term) { |
||
| 137 | return Str::contains(Str::lower($tag), $term); |
||
| 138 | })) { |
||
| 139 | return true; |
||
| 140 | }; |
||
| 141 | |||
| 142 | return false; |
||
| 143 | })->map(function ($adminPage) { |
||
| 144 | return [ |
||
| 145 | 'label' => $adminPage['label'], |
||
| 146 | 'url' => $adminPage['url'], |
||
| 147 | ]; |
||
| 148 | })->toArray(); |
||
| 149 | |||
| 150 | if (count($models) === 0) { |
||
| 151 | return []; |
||
| 152 | } |
||
| 153 | |||
| 154 | return [ |
||
| 155 | [ |
||
| 156 | 'label' => 'Chief', |
||
| 157 | 'models' => $models, |
||
| 158 | ], |
||
| 197 |