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