Completed
Pull Request — master (#17)
by
unknown
01:46 queued 22s
created

SktmController::edit()   B

Complexity

Conditions 5
Paths 12

Size

Total Lines 43
Code Lines 28

Duplication

Lines 43
Ratio 100 %

Importance

Changes 0
Metric Value
cc 5
eloc 28
nc 12
nop 1
dl 43
loc 43
rs 8.439
c 0
b 0
f 0
1
<?php
2
3
namespace Bantenprov\Sktm\Http\Controllers;
4
5
/* Require */
6
use App\Http\Controllers\Controller;
7
use Illuminate\Http\Request;
8
use Illuminate\Support\Facades\DB;
9
use Bantenprov\Sktm\Facades\SktmFacade;
10
11
/* Models */
12
use Bantenprov\Sktm\Models\Bantenprov\Sktm\Sktm;
13
use Bantenprov\Siswa\Models\Bantenprov\Siswa\Siswa;
14
use Bantenprov\Sktm\Models\Bantenprov\Sktm\MasterSktm;
15
use App\User;
16
use Bantenprov\Nilai\Models\Bantenprov\Nilai\Nilai;
17
18
/* Etc */
19
use Validator;
20
use Auth;
21
22
/**
23
 * The SktmController class.
24
 *
25
 * @package Bantenprov\Sktm
26
 * @author  bantenprov <[email protected]>
27
 */
28
class SktmController extends Controller
29
{
30
    protected $sktm;
31
    protected $siswa;
32
    protected $master_sktm;
33
    protected $user;
34
    protected $nilai;
35
36
    /**
37
     * Create a new controller instance.
38
     *
39
     * @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...
40
     */
41
    public function __construct()
42
    {
43
        $this->sktm         = new Sktm;
44
        $this->siswa        = new Siswa;
45
        $this->master_sktm  = new MasterSktm;
46
        $this->user         = new User;
47
        $this->nilai        = new Nilai;
48
    }
49
50
    /**
51
     * Display a listing of the resource.
52
     *
53
     * @return \Illuminate\Http\Response
54
     */
55 View Code Duplication
    public function index(Request $request)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
56
    {
57
        if (request()->has('sort')) {
58
            list($sortCol, $sortDir) = explode('|', request()->sort);
59
60
            $query = $this->sktm->orderBy($sortCol, $sortDir);
61
        } else {
62
            $query = $this->sktm->orderBy('id', 'asc');
63
        }
64
65
        if ($request->exists('filter')) {
66
            $query->where(function($q) use($request) {
67
                $value = "%{$request->filter}%";
68
69
                $q->where('nomor_un', 'like', $value)
70
                    ->orWhere('no_sktm', 'like', $value);
71
            });
72
        }
73
74
        $perPage    = request()->has('per_page') ? (int) request()->per_page : null;
75
76
        $response   = $query->with(['siswa', 'master_sktm', 'user'])->paginate($perPage);
77
78
        return response()->json($response)
79
            ->header('Access-Control-Allow-Origin', '*')
80
            ->header('Access-Control-Allow-Methods', 'GET');
81
    }
82
83
    /**
84
     * Display a listing of the resource.
85
     *
86
     * @return \Illuminate\Http\Response
87
     */
88 View Code Duplication
    public function get()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
89
    {
90
        $sktms = $this->sktm->with(['siswa', 'master_sktm', 'user'])->get();
91
92
        $response['sktms']  = $sktms;
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...
93
        $response['error']      = false;
94
        $response['message']    = 'Success';
95
        $response['status']     = true;
96
97
        return response()->json($response);
98
    }
99
100
    /**
101
     * Show the form for creating a new resource.
102
     *
103
     * @return \Illuminate\Http\Response
104
     */
105 View Code Duplication
    public function create()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
106
    {
107
        $user_id        = isset(Auth::User()->id) ? Auth::User()->id : null;
108
        $sktm           = $this->sktm->getAttributes();
109
        $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...
110
        $users_special  = $this->user->all();
111
        $users_standar  = $this->user->findOrFail($user_id);
112
        $current_user   = Auth::User();
113
114
        $role_check = Auth::User()->hasRole(['superadministrator','administrator']);
115
116
        if ($role_check) {
117
            $user_special = true;
118
119
            foreach ($users_special as $user) {
120
                array_set($user, 'label', $user->name);
121
            }
122
123
            $users = $users_special;
124
        } else {
125
            $user_special = false;
126
127
            array_set($users_standar, 'label', $users_standar->name);
128
129
            $users = $users_standar;
130
        }
131
132
        array_set($current_user, 'label', $current_user->name);
133
134
        $response['sktm']           = $sktm;
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...
135
        $response['users']          = $users;
136
        $response['user_special']   = $user_special;
137
        $response['current_user']   = $current_user;
138
        $response['error']          = false;
139
        $response['message']        = 'Success';
140
        $response['status']         = true;
141
142
        return response()->json($response);
143
    }
144
145
    /**
146
     * Store a newly created resource in storage.
147
     *
148
     * @param  \Illuminate\Http\Request  $request
149
     * @return \Illuminate\Http\Response
150
     */
151
    public function store(Request $request)
152
    {
153
        $sktm = $this->sktm;
154
155
        $validator = Validator::make($request->all(), [
156
            'nomor_un'          => "required|exists:{$this->siswa->getTable()},nomor_un|unique:{$this->sktm->getTable()},nomor_un,NULL,id,deleted_at,NULL",
157
            'master_sktm_id'    => "required|exists:{$this->master_sktm->getTable()},id",
158
            'no_sktm'           => 'required|max:255',
159
            // 'nilai'             => 'required|numeric|min:0|max:100',
0 ignored issues
show
Unused Code Comprehensibility introduced by
58% 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...
160
            'user_id'           => "required|exists:{$this->user->getTable()},id",
161
        ]);
162
163 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...
164
            $error      = true;
165
            $message    = $validator->errors()->first();
166
        } else {
167
            $sktm_master_sktm_id    = $request->input('master_sktm_id');
168
            $master_sktm            = $this->master_sktm->findOrFail($sktm_master_sktm_id);
169
170
            $sktm->nomor_un         = $request->input('nomor_un');
171
            $sktm->master_sktm_id   = $sktm_master_sktm_id;
172
            $sktm->no_sktm          = $request->input('no_sktm');
173
            $sktm->nilai            = $master_sktm->nilai;
174
            $sktm->user_id          = $request->input('user_id');
175
176
            $nilai = $this->nilai->updateOrCreate(
177
                [
178
                    'nomor_un'  => $sktm->nomor_un,
179
                ],
180
                [
181
                    'sktm'      => $sktm->nilai,
182
                    'total'     => null,
183
                    'user_id'   => $sktm->user_id,
184
                ]
185
            );
186
187
            DB::beginTransaction();
188
189
            if ($sktm->save() && $nilai->save())
190
            {
191
                DB::commit();
192
193
                $error      = false;
194
                $message    = 'Success';
195
            } else {
196
                DB::rollBack();
197
198
                $error      = true;
199
                $message    = 'Failed';
200
            }
201
        }
202
203
        $response['sktm']       = $sktm;
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...
204
        $response['error']      = $error;
205
        $response['message']    = $message;
206
        $response['status']     = true;
207
208
        return response()->json($response);
209
    }
210
211
    /**
212
     * Display the specified resource.
213
     *
214
     * @param  \App\Sktm  $nilai
0 ignored issues
show
Bug introduced by
There is no parameter named $nilai. 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...
215
     * @return \Illuminate\Http\Response
216
     */
217 View Code Duplication
    public function show($id)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
218
    {
219
        $sktm = $this->sktm->with(['siswa', 'master_sktm', 'user'])->findOrFail($id);
220
221
        $response['sktm']       = $sktm;
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...
222
        $response['error']      = false;
223
        $response['message']    = 'Success';
224
        $response['status']     = true;
225
226
        return response()->json($response);
227
    }
228
229
    /**
230
     * Show the form for editing the specified resource.
231
     *
232
     * @param  \App\Sktm  $nilai
0 ignored issues
show
Bug introduced by
There is no parameter named $nilai. 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...
233
     * @return \Illuminate\Http\Response
234
     */
235 View Code Duplication
    public function edit($id)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
236
    {
237
        $user_id        = isset(Auth::User()->id) ? Auth::User()->id : null;
238
        $sktm           = $this->sktm->with(['siswa', 'master_sktm', 'user'])->findOrFail($id);
239
        $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...
240
        $users_special  = $this->user->all();
241
        $users_standar  = $this->user->findOrFail($user_id);
242
        $current_user   = Auth::User();
243
244
        if ($sktm->user !== null) {
245
            array_set($sktm->user, 'label', $sktm->user->name);
246
        }
247
248
        $role_check = Auth::User()->hasRole(['superadministrator','administrator']);
249
250
        if ($role_check) {
251
            $user_special = true;
252
253
            foreach ($users_special as $user) {
254
                array_set($user, 'label', $user->name);
255
            }
256
257
            $users = $users_special;
258
        } else {
259
            $user_special = false;
260
261
            array_set($users_standar, 'label', $users_standar->name);
262
263
            $users = $users_standar;
264
        }
265
266
        array_set($current_user, 'label', $current_user->name);
267
268
        $response['sktm']           = $sktm;
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...
269
        $response['users']          = $users;
270
        $response['user_special']   = $user_special;
271
        $response['current_user']   = $current_user;
272
        $response['error']          = false;
273
        $response['message']        = 'Success';
274
        $response['status']         = true;
275
276
        return response()->json($response);
277
    }
278
279
    /**
280
     * Update the specified resource in storage.
281
     *
282
     * @param  \Illuminate\Http\Request  $request
283
     * @param  \App\Sktm  $nilai
0 ignored issues
show
Bug introduced by
There is no parameter named $nilai. 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...
284
     * @return \Illuminate\Http\Response
285
     */
286
    public function update(Request $request, $id)
287
    {
288
        $sktm = $this->sktm->with(['siswa', 'master_sktm', 'user'])->findOrFail($id);
289
290
        $validator = Validator::make($request->all(), [
291
            // 'nomor_un'          => "required|exists:{$this->siswa->getTable()},nomor_un|unique:{$this->sktm->getTable()},nomor_un,{$id},id,deleted_at,NULL",
0 ignored issues
show
Unused Code Comprehensibility introduced by
58% 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...
292
            'master_sktm_id'    => "required|exists:{$this->master_sktm->getTable()},id",
293
            'no_sktm'           => 'required|max:255',
294
            // 'nilai'             => 'required|numeric|min:0|max:100',
0 ignored issues
show
Unused Code Comprehensibility introduced by
58% 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...
295
            'user_id'           => "required|exists:{$this->user->getTable()},id",
296
        ]);
297
298 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...
299
            $error      = true;
300
            $message    = $validator->errors()->first();
301
        } else {
302
            $sktm_master_sktm_id    = $request->input('master_sktm_id');
303
            $master_sktm            = $this->master_sktm->findOrFail($sktm_master_sktm_id);
304
305
            $sktm->nomor_un         = $request->input('nomor_un');
306
            $sktm->master_sktm_id   = $sktm_master_sktm_id;
307
            $sktm->no_sktm          = $request->input('no_sktm');
308
            $sktm->nilai            = $master_sktm->nilai;
309
            $sktm->user_id          = $request->input('user_id');
310
311
            $nilai = $this->nilai->updateOrCreate(
312
                [
313
                    'nomor_un'  => $sktm->nomor_un,
314
                ],
315
                [
316
                    'sktm'      => $sktm->nilai,
317
                    'total'     => null,
318
                    'user_id'   => $sktm->user_id,
319
                ]
320
            );
321
322
            DB::beginTransaction();
323
324
            if ($sktm->save() && $nilai->save())
325
            {
326
                DB::commit();
327
328
                $error      = false;
329
                $message    = 'Success';
330
            } else {
331
                DB::rollBack();
332
333
                $error      = true;
334
                $message    = 'Failed';
335
            }
336
        }
337
338
        $response['sktm']       = $sktm;
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...
339
        $response['error']      = $error;
340
        $response['message']    = $message;
341
        $response['status']     = true;
342
343
        return response()->json($response);
344
    }
345
346
    /**
347
     * Remove the specified resource from storage.
348
     *
349
     * @param  \App\Sktm  $nilai
0 ignored issues
show
Bug introduced by
There is no parameter named $nilai. 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...
350
     * @return \Illuminate\Http\Response
351
     */
352
    public function destroy($id)
353
    {
354
        $sktm = $this->sktm->findOrFail($id);
355
356
        $nilai = $this->nilai->updateOrCreate(
357
            [
358
                'nomor_un'  => $sktm->nomor_un,
359
            ],
360
            [
361
                'sktm'      => 0,
362
                'total'     => null,
363
                'user_id'   => $sktm->user_id,
364
            ]
365
        );
366
367
        DB::beginTransaction();
368
369
        if ($sktm->delete() && $nilai->save())
370
        {
371
            DB::commit();
372
373
            $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...
374
            $response['success']    = true;
375
        } else {
376
            DB::rollBack();
377
378
            $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...
379
            $response['success']    = false;
380
        }
381
382
        $response['status']     = true;
383
384
        return json_encode($response);
385
    }
386
}
387