| Conditions | 2 |
| Paths | 1 |
| Total Lines | 58 |
| Code Lines | 40 |
| 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 |
||
| 56 | public function all(): Collection |
||
| 57 | { |
||
| 58 | return app('cache.array')->rememberForever(__CLASS__ . __METHOD__, static function (): Collection { |
||
| 59 | // All trees |
||
| 60 | $query = DB::table('gedcom') |
||
| 61 | ->leftJoin('gedcom_setting', static function (JoinClause $join): void { |
||
| 62 | $join->on('gedcom_setting.gedcom_id', '=', 'gedcom.gedcom_id') |
||
| 63 | ->where('gedcom_setting.setting_name', '=', 'title'); |
||
| 64 | }) |
||
| 65 | ->where('gedcom.gedcom_id', '>', 0) |
||
| 66 | ->select([ |
||
| 67 | 'gedcom.gedcom_id AS tree_id', |
||
| 68 | 'gedcom.gedcom_name AS tree_name', |
||
| 69 | 'gedcom_setting.setting_value AS tree_title', |
||
| 70 | ]) |
||
| 71 | ->orderBy('gedcom.sort_order') |
||
| 72 | ->orderBy('gedcom_setting.setting_value'); |
||
| 73 | |||
| 74 | // Non-admins may not see all trees |
||
| 75 | if (!Auth::isAdmin()) { |
||
| 76 | $query |
||
| 77 | ->join('gedcom_setting AS gs2', static function (JoinClause $join): void { |
||
| 78 | $join->on('gs2.gedcom_id', '=', 'gedcom.gedcom_id') |
||
| 79 | ->where('gs2.setting_name', '=', 'imported'); |
||
| 80 | }) |
||
| 81 | ->join('gedcom_setting AS gs3', static function (JoinClause $join): void { |
||
| 82 | $join->on('gs3.gedcom_id', '=', 'gedcom.gedcom_id') |
||
| 83 | ->where('gs3.setting_name', '=', 'REQUIRE_AUTHENTICATION'); |
||
| 84 | }) |
||
| 85 | ->leftJoin('user_gedcom_setting', static function (JoinClause $join): void { |
||
| 86 | $join->on('user_gedcom_setting.gedcom_id', '=', 'gedcom.gedcom_id') |
||
| 87 | ->where('user_gedcom_setting.user_id', '=', Auth::id()) |
||
| 88 | ->where('user_gedcom_setting.setting_name', '=', 'canedit'); |
||
| 89 | }) |
||
| 90 | ->where(static function (Builder $query): void { |
||
| 91 | $query |
||
| 92 | // Managers |
||
| 93 | ->where('user_gedcom_setting.setting_value', '=', 'admin') |
||
| 94 | // Members |
||
| 95 | ->orWhere(static function (Builder $query): void { |
||
| 96 | $query |
||
| 97 | ->where('gs2.setting_value', '=', '1') |
||
| 98 | ->where('gs3.setting_value', '=', '1') |
||
| 99 | ->where('user_gedcom_setting.setting_value', '<>', 'none'); |
||
| 100 | }) |
||
| 101 | // Public trees |
||
| 102 | ->orWhere(static function (Builder $query): void { |
||
| 103 | $query |
||
| 104 | ->where('gs2.setting_value', '=', '1') |
||
| 105 | ->where('gs3.setting_value', '<>', '1'); |
||
| 106 | }); |
||
| 107 | }); |
||
| 108 | } |
||
| 109 | |||
| 110 | return $query |
||
| 111 | ->get() |
||
| 112 | ->mapWithKeys(static function (stdClass $row): array { |
||
| 113 | return [$row->tree_id => Tree::rowMapper()($row)]; |
||
| 114 | }); |
||
| 236 |