| Conditions | 11 |
| Paths | 49 |
| Total Lines | 50 |
| Code Lines | 28 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| 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 |
||
| 87 | public function destroy($id) |
||
| 88 | { |
||
| 89 | try { |
||
| 90 | if ($id) { |
||
| 91 | $releases = new Releases; |
||
| 92 | $releases->deleteMultiple($id); |
||
| 93 | |||
| 94 | // Handle AJAX requests |
||
| 95 | if (request()->wantsJson() || request()->ajax()) { |
||
| 96 | return response()->json([ |
||
| 97 | 'success' => true, |
||
| 98 | 'message' => 'Release deleted successfully', |
||
| 99 | ]); |
||
| 100 | } |
||
| 101 | |||
| 102 | session()->flash('success', 'Release deleted successfully'); |
||
| 103 | } |
||
| 104 | |||
| 105 | // Handle AJAX requests |
||
| 106 | if (request()->wantsJson() || request()->ajax()) { |
||
| 107 | return response()->json([ |
||
| 108 | 'success' => false, |
||
| 109 | 'message' => 'No release ID provided', |
||
| 110 | ], 400); |
||
| 111 | } |
||
| 112 | |||
| 113 | // Check if request is coming from the NZB details page |
||
| 114 | $referer = request()->headers->get('referer'); |
||
| 115 | if ($referer && str_contains($referer, '/details/')) { |
||
| 116 | // If coming from details page, redirect to home page |
||
| 117 | return redirect()->route('All'); |
||
| 118 | } |
||
| 119 | |||
| 120 | // Default redirection logic for other cases |
||
| 121 | $redirectUrl = session('intended_redirect') ?? route('admin.release-list'); |
||
| 122 | session()->forget('intended_redirect'); |
||
| 123 | |||
| 124 | return redirect($redirectUrl); |
||
| 125 | } catch (\Exception $e) { |
||
| 126 | // Handle AJAX requests |
||
| 127 | if (request()->wantsJson() || request()->ajax()) { |
||
| 128 | return response()->json([ |
||
| 129 | 'success' => false, |
||
| 130 | 'message' => 'Error deleting release: '.$e->getMessage(), |
||
| 131 | ], 500); |
||
| 132 | } |
||
| 133 | |||
| 134 | session()->flash('error', 'Error deleting release: '.$e->getMessage()); |
||
| 135 | |||
| 136 | return redirect()->route('admin.release-list'); |
||
| 137 | } |
||
| 140 |
The
breakstatement is not necessary if it is preceded for example by areturnstatement:If you would like to keep this construct to be consistent with other
casestatements, you can safely mark this issue as a false-positive.