Completed
Push — master ( f8ff77...d44702 )
by
unknown
12s
created

SiswaController::create()   F

Complexity

Conditions 10
Paths 384

Size

Total Lines 77
Code Lines 50

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 10
eloc 50
nc 384
nop 1
dl 0
loc 77
rs 3.913
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

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:

1
<?php
2
3
namespace Bantenprov\Siswa\Http\Controllers;
4
5
/* Require */
6
use App\Http\Controllers\Controller;
7
use Illuminate\Http\Request;
8
use Bantenprov\Siswa\Facades\SiswaFacade;
9
10
/* Models */
11
use Bantenprov\Siswa\Models\Bantenprov\Siswa\Siswa;
12
use Laravolt\Indonesia\Models\Province;
13
use Laravolt\Indonesia\Models\City;
14
use Laravolt\Indonesia\Models\District;
15
use Laravolt\Indonesia\Models\Village;
16
use Bantenprov\Sekolah\Models\Bantenprov\Sekolah\Sekolah;
17
use Bantenprov\Sekolah\Models\Bantenprov\Sekolah\ProdiSekolah;
18
use App\User;
19
20
/* Etc */
21
use Validator;
22
use Auth;
23
24
/**
25
 * The SiswaController class.
26
 *
27
 * @package Bantenprov\Siswa
28
 * @author  bantenprov <[email protected]>
29
 */
30
class SiswaController extends Controller
31
{
32
    protected $siswa;
33
    protected $province;
34
    protected $city;
35
    protected $district;
36
    protected $village;
37
    protected $sekolah;
38
    protected $prodi_sekolah;
39
    protected $user;
40
41
    /**
42
     * Create a new controller instance.
43
     *
44
     * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

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.

Loading history...
45
     */
46
    public function __construct()
47
    {
48
        $this->siswa            = new Siswa;
49
        $this->province         = new Province;
50
        $this->city             = new City;
51
        $this->district         = new District;
52
        $this->village          = new Village;
53
        $this->sekolah          = new Sekolah;
54
        $this->prodi_sekolah    = new ProdiSekolah;
55
        $this->user             = new User;
56
    }
57
58
    /**
59
     * Display a listing of the resource.
60
     *
61
     * @return \Illuminate\Http\Response
62
     */
63
    public function index(Request $request)
64
    {
65
        if (request()->has('sort')) {
66
            list($sortCol, $sortDir) = explode('|', request()->sort);
67
68
            $query = $this->siswa->orderBy($sortCol, $sortDir);
69
        } else {
70
            $query = $this->siswa->orderBy('id', 'asc');
71
        }
72
73
        if ($request->exists('filter')) {
74
            $query->where(function($q) use($request) {
75
                $value = "%{$request->filter}%";
76
77
                $q->where('nomor_un', 'like', $value)
78
                    ->orWhere('nik', 'like', $value)
79
                    ->orWhere('nama_siswa', 'like', $value)
80
                    ->orWhere('no_kk', 'like', $value)
81
                    ->orWhere('nisn', 'like', $value);
82
            });
83
        }
84
85
        $perPage    = request()->has('per_page') ? (int) request()->per_page : null;
86
87
        $response   = $query->with(['province', 'city', 'district', 'village', 'sekolah', 'prodi_sekolah', 'user'])->paginate($perPage);
88
89
        foreach($response as $siswa){
90
            if (isset($siswa->prodi_sekolah->program_keahlian)) {
91
                $siswa->prodi_sekolah->program_keahlian;
92
            }
93
        }
94
95
        return response()->json($response)
96
            ->header('Access-Control-Allow-Origin', '*')
97
            ->header('Access-Control-Allow-Methods', 'GET');
98
    }
99
100
    /**
101
     * Display a listing of the resource.
102
     *
103
     * @return \Illuminate\Http\Response
104
     */
105
    public function get()
106
    {
107
        $siswas = $this->siswa->with(['province', 'city', 'district', 'village', 'sekolah', 'prodi_sekolah', 'user'])->get();
108
109
        foreach($siswas as $siswa){
110
            array_set($siswa, 'label', $siswa->nama_siswa);
111
112
            if (isset($siswa->prodi_sekolah->program_keahlian)) {
113
                $siswa->prodi_sekolah->program_keahlian;
114
            }
115
        }
116
117
        $response['siswas']   = $siswas;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$response was never initialized. Although not strictly required by PHP, it is generally a good practice to add $response = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
118
        $response['error']      = false;
119
        $response['message']    = 'Success';
120
        $response['status']     = true;
121
122
        return response()->json($response);
123
    }
124
125
    /**
126
     * Show the form for creating a new resource.
127
     *
128
     * @return \Illuminate\Http\Response
129
     */
130
    public function create(Request $request)
131
    {
132
        $user_id        = isset(Auth::User()->id) ? Auth::User()->id : null;
133
        $siswa          = $this->siswa->getAttributes();
134
        $provinces      = $this->province->getAttributes();
135
        $cities         = $this->city->getAttributes();
136
        $districts      = $this->district->getAttributes();
137
        $villages       = $this->village->getAttributes();
138
        $sekolahs       = $this->sekolah->get();
139
        $prodi_sekolahs = $this->prodi_sekolah->get();
140
        $users          = $this->user->getAttributes();
0 ignored issues
show
Unused Code introduced by
$users is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
141
        $users_special  = $this->user->all();
142
        $users_standar  = $this->user->findOrFail($user_id);
143
        $current_user   = Auth::User();
144
145
        // dd($prodi_sekolahs);
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
146
147
        foreach($provinces as $province){
148
            array_set($province, 'label', $province->name);
149
        }
150
151
        foreach($cities as $city){
152
            array_set($city, 'label', $city->name);
153
        }
154
155
        foreach($districts as $district){
156
            array_set($district, 'label', $district->name);
157
        }
158
159
        foreach($villages as $village){
160
            array_set($village, 'label', $village->name);
161
        }
162
163
        foreach($sekolahs as $sekolah){
164
            array_set($sekolah, 'label', $sekolah->nama);
165
        }
166
167
        foreach($prodi_sekolahs as $prodi_sekolah){
168
            array_set($prodi_sekolah, 'label', $prodi_sekolah->keterangan);
169
        }
170
171
        $role_check = Auth::User()->hasRole(['superadministrator','administrator']);
172
173
        if($role_check){
174
            $user_special = true;
175
176
            foreach($users_special as $user){
177
                array_set($user, 'label', $user->name);
178
            }
179
180
            $users = $users_special;
181
        }else{
182
            $user_special = false;
183
184
            array_set($users_standar, 'label', $users_standar->name);
185
186
            $users = $users_standar;
187
        }
188
189
        array_set($current_user, 'label', $current_user->name);
190
191
        $response['siswa']          = $siswa;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$response was never initialized. Although not strictly required by PHP, it is generally a good practice to add $response = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
192
        $response['provinces']      = $provinces;
193
        $response['cities']         = $cities;
194
        $response['districts']      = $districts;
195
        $response['villages']       = $villages;
196
        $response['sekolahs']       = $sekolahs;
197
        $response['prodi_sekolahs'] = $prodi_sekolahs;
198
        $response['users']          = $users;
199
        $response['user_special']   = $user_special;
200
        $response['current_user']   = $current_user;
201
        $response['error']          = false;
202
        $response['message']        = 'Success';
203
        $response['status']         = true;
204
205
        return response()->json($response);
206
    }
207
208
    /**
209
     * Store a newly created resource in storage.
210
     *
211
     * @param  \Illuminate\Http\Request  $request
212
     * @return \Illuminate\Http\Response
213
     */
214
    public function store(Request $request)
215
    {
216
        $siswa      = $this->siswa;
217
        $validator  = Validator::make($request->all(), [
218
            'nomor_un'          => "required|max:255|unique:{$this->siswa->getTable()},nomor_un,NULL,id,deleted_at,NULL",
219
            'nik'               => "required|digits:16|unique:{$this->siswa->getTable()},nik,NULL,id,deleted_at,NULL",
220
            'nama_siswa'        => 'required|max:255',
221
            'no_kk'             => "required|digits:16|unique:{$this->siswa->getTable()},no_kk,NULL,id,deleted_at,NULL",
222
            'alamat_kk'         => 'required|max:255',
223
            'province_id'       => "required|exists:{$this->province->getTable()},id",
224
            'city_id'           => "required|exists:{$this->city->getTable()},id",
225
            'district_id'       => "required|exists:{$this->district->getTable()},id",
226
            'village_id'        => "required|exists:{$this->village->getTable()},id",
227
            'tempat_lahir'      => 'required|max:255',
228
            'tgl_lahir'         => 'required|date',
229
            'jenis_kelamin'     => 'required|max:255',
230
            'agama'             => 'required|max:255',
231
            'nisn'              => "required|between:6,15|unique:{$this->siswa->getTable()},nisn,NULL,id,deleted_at,NULL",
232
            'tahun_lulus'       => 'required|date_format:Y',
233
            'sekolah_id'        => "required|exists:{$this->sekolah->getTable()},id",
234
            'prodi_sekolah_id'  => "required|exists:{$this->prodi_sekolah->getTable()},id",
235
            'user_id'           => "required|exists:{$this->user->getTable()},id",
236
        ]);
237
238 View Code Duplication
        if ($validator->fails()) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
239
            $error      = true;
240
            $message    = $validator->errors()->first();
241
        } else {
242
            $siswa->user_id             = $request->input('user_id');
243
            $siswa->nomor_un            = $request->input('nomor_un');
244
            $siswa->nik                 = $request->input('nik');
245
            $siswa->nama_siswa          = $request->input('nama_siswa');
246
            $siswa->no_kk               = $request->input('no_kk');
247
            $siswa->alamat_kk           = $request->input('alamat_kk');
248
            $siswa->province_id         = $request->input('province_id');
249
            $siswa->city_id             = $request->input('city_id');
250
            $siswa->district_id         = $request->input('district_id');
251
            $siswa->village_id          = $request->input('village_id');
252
            $siswa->tempat_lahir        = $request->input('tempat_lahir');
253
            $siswa->tgl_lahir           = $request->input('tgl_lahir');
254
            $siswa->jenis_kelamin       = $request->input('jenis_kelamin');
255
            $siswa->agama               = $request->input('agama');
256
            $siswa->nisn                = $request->input('nisn');
257
            $siswa->sekolah_id          = $request->input('sekolah_id');
258
            $siswa->prodi_sekolah_id    = $request->input('prodi_sekolah_id');
259
            $siswa->tahun_lulus         = $request->input('tahun_lulus');
260
            $siswa->save();
261
262
            $error      = false;
263
            $message    = 'Success';
264
        }
265
266
        $response['siswa']      = $siswa;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$response was never initialized. Although not strictly required by PHP, it is generally a good practice to add $response = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
267
        $response['error']      = $error;
268
        $response['message']    = $message;
269
        $response['status']     = true;
270
271
        return response()->json($response);
272
    }
273
274
    /**
275
     * Display the specified resource.
276
     *
277
     * @param  \App\Siswa  $siswa
0 ignored issues
show
Bug introduced by
There is no parameter named $siswa. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
278
     * @return \Illuminate\Http\Response
279
     */
280
    public function show($id)
281
    {
282
        $siswa = $this->siswa->with(['province', 'city', 'district', 'village', 'sekolah', 'prodi_sekolah', 'user'])->findOrFail($id);
283
284
        if (isset($siswa->prodi_sekolah->program_keahlian)) {
285
            $siswa->prodi_sekolah->program_keahlian;
286
        }
287
288
        $response['siswa']      = $siswa;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$response was never initialized. Although not strictly required by PHP, it is generally a good practice to add $response = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
289
        $response['error']      = false;
290
        $response['message']    = 'Success';
291
        $response['status']     = true;
292
293
        return response()->json($response);
294
    }
295
296
    /**
297
     * Show the form for editing the specified resource.
298
     *
299
     * @param  \App\Siswa  $siswa
0 ignored issues
show
Bug introduced by
There is no parameter named $siswa. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
300
     * @return \Illuminate\Http\Response
301
     */
302
    public function edit($id)
303
    {
304
        $siswa = $this->siswa->with(['province', 'city', 'district', 'village', 'sekolah', 'prodi_sekolah', 'user'])->findOrFail($id);
305
306
        $response['siswa']['province'] = array_add($siswa->province, 'label', $siswa->province->name);
0 ignored issues
show
Coding Style Comprehensibility introduced by
$response was never initialized. Although not strictly required by PHP, it is generally a good practice to add $response = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
307
308
        $response['siswa']['city'] = array_add($siswa->city, 'label', $siswa->city->name);
309
310
        $response['siswa']['district'] = array_add($siswa->district, 'label', $siswa->district->name);
311
312
        $response['siswa']['village'] = array_add($siswa->village, 'label', $siswa->village->name);
313
314
        $response['siswa']['sekolah'] = array_add($siswa->sekolah, 'label', $siswa->sekolah->nama);
315
316
        $response['siswa']['prodi_sekolah'] = array_add($siswa->prodi_sekolah, 'label', $siswa->prodi_sekolah->keterangan);
317
318
319
320
        $response['siswa']      = $siswa;
321
        $response['error']      = false;
322
        $response['message']    = 'Success';
323
        $response['status']     = true;
324
325
        return response()->json($response);
326
    }
327
328
    /**
329
     * Update the specified resource in storage.
330
     *
331
     * @param  \Illuminate\Http\Request  $request
332
     * @param  \App\Siswa  $siswa
0 ignored issues
show
Bug introduced by
There is no parameter named $siswa. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
333
     * @return \Illuminate\Http\Response
334
     */
335
    public function update(Request $request, $id)
336
    {
337
        $siswa = $this->siswa->with(['province', 'city', 'district', 'village', 'sekolah', 'prodi_sekolah', 'user'])->findOrFail($id);
338
339
            $validator = Validator::make($request->all(), [
340
                'nomor_un'          => "required|max:255|unique:{$this->siswa->getTable()},nomor_un,{$id},id,deleted_at,NULL",
341
                'nik'               => "required|digits:16|unique:{$this->siswa->getTable()},nik,{$id},id,deleted_at,NULL",
342
                'nama_siswa'        => 'required|max:255',
343
                'no_kk'             => "required|digits:16|unique:{$this->siswa->getTable()},no_kk,{$id},id,deleted_at,NULL",
344
                'alamat_kk'         => 'required|max:255',
345
                'province_id'       => "required|exists:{$this->province->getTable()},id",
346
                'city_id'           => "required|exists:{$this->city->getTable()},id",
347
                'district_id'       => "required|exists:{$this->district->getTable()},id",
348
                'village_id'        => "required|exists:{$this->village->getTable()},id",
349
                'tempat_lahir'      => 'required|max:255',
350
                'tgl_lahir'         => 'required|date',
351
                'jenis_kelamin'     => 'required|max:255',
352
                'agama'             => 'required|max:255',
353
                'nisn'              => "required|between:4,17|unique:{$this->siswa->getTable()},nisn,{$id},id,deleted_at,NULL",
354
                'tahun_lulus'       => 'required|date_format:Y',
355
                'sekolah_id'        => "required|exists:{$this->sekolah->getTable()},id",
356
                'prodi_sekolah_id'  => "required|exists:{$this->prodi_sekolah->getTable()},id",
357
                'user_id'           => "required|exists:{$this->user->getTable()},id",
358
359
                ]);
360
361 View Code Duplication
            if ($validator->fails()) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
362
            $error      = true;
363
            $message    = $validator->errors()->first();
364
365
            } else {
366
                $siswa->user_id             = $request->input('user_id');
367
                $siswa->nomor_un            = $request->input('nomor_un');
368
                $siswa->nik                 = $request->input('nik');
369
                $siswa->nama_siswa          = $request->input('nama_siswa');
370
                $siswa->no_kk               = $request->input('no_kk');
371
                $siswa->alamat_kk           = $request->input('alamat_kk');
372
                $siswa->province_id         = $request->input('province_id');
373
                $siswa->city_id             = $request->input('city_id');
374
                $siswa->district_id         = $request->input('district_id');
375
                $siswa->village_id          = $request->input('village_id');
376
                $siswa->tempat_lahir        = $request->input('tempat_lahir');
377
                $siswa->tgl_lahir           = $request->input('tgl_lahir');
378
                $siswa->jenis_kelamin       = $request->input('jenis_kelamin');
379
                $siswa->agama               = $request->input('agama');
380
                $siswa->nisn                = $request->input('nisn');
381
                $siswa->sekolah_id          = $request->input('sekolah_id');
382
                $siswa->prodi_sekolah_id    = $request->input('prodi_sekolah_id');
383
                $siswa->tahun_lulus         = $request->input('tahun_lulus');
384
                $siswa->save();
385
386
                $error      = false;
387
                $message    = 'Success';
388
            }
389
390
        $response['error']      = $error;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$response was never initialized. Although not strictly required by PHP, it is generally a good practice to add $response = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
391
        $response['message']    = $message;
392
        $response['status']     = true;
393
394
        return response()->json($response);
395
    }
396
397
    /**
398
     * Remove the specified resource from storage.
399
     *
400
     * @param  \App\Siswa  $siswa
0 ignored issues
show
Bug introduced by
There is no parameter named $siswa. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
401
     * @return \Illuminate\Http\Response
402
     */
403
    public function destroy($id)
404
    {
405
        $siswa = $this->siswa->findOrFail($id);
406
407
        if ($siswa->delete()) {
408
            $response['message']    = 'Success';
0 ignored issues
show
Coding Style Comprehensibility introduced by
$response was never initialized. Although not strictly required by PHP, it is generally a good practice to add $response = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
409
            $response['success']    = true;
410
            $response['status']     = true;
411
        } else {
412
            $response['message']    = 'Failed';
0 ignored issues
show
Coding Style Comprehensibility introduced by
$response was never initialized. Although not strictly required by PHP, it is generally a good practice to add $response = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
413
            $response['success']    = false;
414
            $response['status']     = false;
415
        }
416
417
        return json_encode($response);
418
    }
419
}
420