Completed
Push — master ( fe6394...28fb23 )
by
unknown
29s queued 27s
created

AdminSekolahController::getBySekolah()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 11
Ratio 100 %

Importance

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