Conditions | 13 |
Paths | 432 |
Total Lines | 61 |
Code Lines | 41 |
Lines | 8 |
Ratio | 13.11 % |
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 |
||
105 | public function show($id, $track = null, Request $request) |
||
106 | { |
||
107 | View Code Duplication | if (request()->has('sort')) { |
|
108 | list($sortCol, $sortDir) = explode('|', request()->sort); |
||
109 | |||
110 | $query = $this->siswa->orderBy($sortCol, $sortDir); |
||
111 | } else { |
||
112 | $query = $this->siswa |
||
113 | ->orderBy('nomor_un', 'asc'); |
||
114 | } |
||
115 | |||
116 | if ($request->exists('filter')) { |
||
117 | $query->where(function($q) use($request) { |
||
118 | $value = "%{$request->filter}%"; |
||
119 | |||
120 | if (Auth::User()->hasRole(['superadministrator'])) { |
||
121 | $q->where('nomor_un', 'like', $value) |
||
122 | ->orWhere('nik', 'like', $value) |
||
123 | ->orWhere('nama_siswa', 'like', $value) |
||
124 | ->orWhere('no_kk', 'like', $value) |
||
125 | ->orWhere('nisn', 'like', $value); |
||
126 | } else { |
||
127 | $q->where('nomor_un', 'like', $value) |
||
128 | ->orWhere('nik', 'like', $value) |
||
129 | ->orWhere('nama_siswa', 'like', $value) |
||
130 | ->orWhere('no_kk', 'like', $value) |
||
131 | ->orWhere('nisn', 'like', $value); |
||
132 | } |
||
133 | }); |
||
134 | } |
||
135 | |||
136 | if (Auth::User()->hasRole(['superadministrator'])) { |
||
137 | $query->where('sekolah_id', '=', $id); |
||
138 | } else if (!is_null($this->admin_sekolah)) { |
||
139 | $query->where('sekolah_id', '=', $this->admin_sekolah->sekolah_id); |
||
140 | } |
||
141 | |||
142 | if ($track == 'umum') { |
||
143 | $query->whereIn('kegiatan_id', ['12', '22']); |
||
144 | } else if ($track == 'prestasi') { |
||
145 | $query->whereIn('kegiatan_id', ['11', '21']); |
||
146 | } |
||
147 | |||
148 | $perPage = request()->has('per_page') ? (int) request()->per_page : null; |
||
149 | |||
150 | if (is_null($this->admin_sekolah) && !Auth::User()->hasRole(['superadministrator'])) { |
||
151 | $response = $query->with(['province', 'city', 'district', 'village', 'sekolah', 'prodi_sekolah', 'user', 'akademik', 'nilai'])->paginate($perPage); |
||
152 | } else { |
||
153 | $response = $query->with(['province', 'city', 'district', 'village', 'sekolah', 'prodi_sekolah', 'user', 'akademik', 'nilai'])->paginate($perPage); |
||
154 | } |
||
155 | |||
156 | foreach ($response as $siswa) { |
||
157 | if (isset($siswa->prodi_sekolah->program_keahlian)) { |
||
158 | $siswa->prodi_sekolah->program_keahlian; |
||
159 | } |
||
160 | } |
||
161 | |||
162 | return response()->json($response) |
||
163 | ->header('Access-Control-Allow-Origin', '*') |
||
164 | ->header('Access-Control-Allow-Methods', 'GET'); |
||
165 | } |
||
166 | } |
||
167 |
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.