| Conditions | 15 |
| Paths | 252 |
| Total Lines | 100 |
| Code Lines | 70 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 1 | 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 |
||
| 25 | public function index(Request $request): void |
||
| 26 | { |
||
| 27 | $this->setAdminPrefs(); |
||
| 28 | |||
| 29 | $meta_title = $title = 'Invitation Management'; |
||
| 30 | |||
| 31 | // Get filter parameters |
||
| 32 | $status = $request->get('status', ''); |
||
| 33 | $invited_by = $request->get('invited_by', ''); |
||
| 34 | $email = $request->get('email', ''); |
||
| 35 | $orderBy = $request->get('ob', 'created_at_desc'); |
||
| 36 | $page = $request->get('page', 1); |
||
|
|
|||
| 37 | |||
| 38 | // Build query |
||
| 39 | $query = Invitation::with(['invitedBy', 'usedBy']); |
||
| 40 | |||
| 41 | // Apply filters |
||
| 42 | if ($status) { |
||
| 43 | switch ($status) { |
||
| 44 | case 'pending': |
||
| 45 | $query->valid(); // Active, not expired, not used |
||
| 46 | break; |
||
| 47 | case 'used': |
||
| 48 | $query->used(); // Has used_at timestamp |
||
| 49 | break; |
||
| 50 | case 'expired': |
||
| 51 | $query->expired(); // expires_at is in the past |
||
| 52 | break; |
||
| 53 | case 'cancelled': |
||
| 54 | $query->where('is_active', false) |
||
| 55 | ->whereNull('used_at'); // Inactive but not used = cancelled |
||
| 56 | break; |
||
| 57 | } |
||
| 58 | } |
||
| 59 | |||
| 60 | if ($invited_by) { |
||
| 61 | $user = User::where('username', 'like', '%'.$invited_by.'%')->first(); |
||
| 62 | if ($user) { |
||
| 63 | $query->where('invited_by', $user->id); |
||
| 64 | } |
||
| 65 | } |
||
| 66 | |||
| 67 | if ($email) { |
||
| 68 | $query->where('email', 'like', '%'.$email.'%'); |
||
| 69 | } |
||
| 70 | |||
| 71 | // Apply ordering |
||
| 72 | switch ($orderBy) { |
||
| 73 | case 'created_at_asc': |
||
| 74 | $query->orderBy('created_at', 'asc'); |
||
| 75 | break; |
||
| 76 | case 'created_at_desc': |
||
| 77 | $query->orderBy('created_at', 'desc'); |
||
| 78 | break; |
||
| 79 | case 'expires_at_asc': |
||
| 80 | $query->orderBy('expires_at', 'asc'); |
||
| 81 | break; |
||
| 82 | case 'expires_at_desc': |
||
| 83 | $query->orderBy('expires_at', 'desc'); |
||
| 84 | break; |
||
| 85 | case 'email_asc': |
||
| 86 | $query->orderBy('email', 'asc'); |
||
| 87 | break; |
||
| 88 | case 'email_desc': |
||
| 89 | $query->orderBy('email', 'desc'); |
||
| 90 | break; |
||
| 91 | default: |
||
| 92 | $query->orderBy('created_at', 'desc'); |
||
| 93 | } |
||
| 94 | |||
| 95 | // Paginate results |
||
| 96 | $invitations = $query->paginate(config('nntmux.items_per_page', 25)); |
||
| 97 | |||
| 98 | // Get overall statistics |
||
| 99 | $stats = $this->getOverallStats(); |
||
| 100 | |||
| 101 | // Get user statistics (top inviters) |
||
| 102 | $topInviters = $this->getTopInviters(); |
||
| 103 | |||
| 104 | $this->smarty->assign([ |
||
| 105 | 'invitations' => $invitations, |
||
| 106 | 'stats' => $stats, |
||
| 107 | 'topInviters' => $topInviters, |
||
| 108 | 'status' => $status, |
||
| 109 | 'invited_by' => $invited_by, |
||
| 110 | 'email' => $email, |
||
| 111 | 'orderBy' => $orderBy, |
||
| 112 | 'statusOptions' => [ |
||
| 113 | '' => 'All', |
||
| 114 | 'pending' => 'Pending', |
||
| 115 | 'used' => 'Used', |
||
| 116 | 'expired' => 'Expired', |
||
| 117 | 'cancelled' => 'Cancelled', |
||
| 118 | ], |
||
| 119 | ]); |
||
| 120 | |||
| 121 | $content = $this->smarty->fetch('admin-invitation-list.tpl'); |
||
| 122 | $this->smarty->assign(compact('title', 'meta_title', 'content')); |
||
| 123 | |||
| 124 | $this->adminrender(); |
||
| 125 | } |
||
| 277 |