Completed
Push — master ( 28fb23...54a620 )
by
unknown
01:38
created

AdminSekolahController::checkRole()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
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
    /**
78
     * Display a listing of the resource.
79
     *
80
     * @return \Illuminate\Http\Response
81
     */
82 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...
83
    {
84
        $admin_sekolahs = $this->admin_sekolah->with(['sekolah', 'user'])->get();
85
86
        $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...
87
        $response['error']          = false;
88
        $response['message']        = 'Success';
89
        $response['status']         = true;
90
91
        return response()->json($response);
92
    }
93
94
    /**
95
     * Display a listing of the resource.
96
     *
97
     * @return \Illuminate\Http\Response
98
     */
99 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...
100
    {
101
        $admin_sekolahs = $this->admin_sekolah->where('sekolah_id', '=', $id)->with(['sekolah', 'user'])->get();
102
103
        $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...
104
        $response['message']        = 'Success';
105
        $response['error']          = false;
106
        $response['status']         = true;
107
108
        return response()->json($response);
109
    }
110
111
    /**
112
     * Show the form for creating a new resource.
113
     *
114
     * @return \Illuminate\Http\Response
115
     */
116
    public function create()
117
    {
118
        $user_id            = isset(Auth::User()->id) ? Auth::User()->id : null;
119
        $admin_sekolah      = $this->admin_sekolah->getAttributes();
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);
0 ignored issues
show
Unused Code introduced by
$users_standar 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...
123
        $current_user       = Auth::User();
124
        $admins             = [];
125
126 View Code Duplication
        foreach($users_special as $user){
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...
127
            if($user->hasRole(['superadministrator','administrator'])){
128
                array_set($user, 'label', $user->name);
129
                array_push($admins, $user);
130
            }
131
        }
132
133
        array_set($current_user, 'label', $current_user->name);
134
135
        $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...
136
        $response['users']              = $admins;
137
        $response['user_special']       = true;
138
        $response['current_user']       = $current_user;
139
        $response['error']              = false;
140
        $response['message']            = 'Success';
141
        $response['status']             = true;
142
143
        return response()->json($response);
144
    }
145
146
    /**
147
     * Store a newly created resource in storage.
148
     *
149
     * @param  \Illuminate\Http\Request  $request
150
     * @return \Illuminate\Http\Response
151
     */
152
    public function store(Request $request)
153
    {
154
        if($this->checkRole(['superadministrator'])){
155
            $admin_sekolah = $this->admin_sekolah;
156
157
            $validator = Validator::make($request->all(), [
158
                'sekolah_id'            => "required|exists:{$this->sekolah->getTable()},id",
159
                'admin_sekolah_id'      => "required|unique:{$this->admin_sekolah->getTable()},admin_sekolah_id,NULL,id,deleted_at,NULL",
160
            ]);
161
162 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...
163
                $error      = true;
164
                $message    = $validator->errors()->first();
165
            } else {
166
                $admin_sekolah->sekolah_id          = $request->input('sekolah_id');
167
                $admin_sekolah->admin_sekolah_id    = $request->input('admin_sekolah_id');
168
                $admin_sekolah->user_id             = Auth::user()->id;
169
                $admin_sekolah->save();
170
171
                $error      = false;
172
                $message    = 'Success';
173
            }
174
175
            $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...
176
            $response['error']          = $error;
177
            $response['message']        = $message;
178
            $response['status']         = true;
179
180
            return response()->json($response);
181
        }else{
182
183
            $response['error']          = true;
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...
184
            $response['message']        = 'Maaf anda Tidak mempunyai hak akses untuk ini.';
185
            $response['status']         = true;
186
187
            return response()->json($response);
188
        }
189
190
    }
191
192
    /**
193
     * Display the specified resource.
194
     *
195
     * @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...
196
     * @return \Illuminate\Http\Response
197
     */
198 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...
199
    {
200
        $admin_sekolah = $this->admin_sekolah->with(['sekolah', 'admin_sekolah', 'user'])->findOrFail($id);
201
202
        $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...
203
        $response['error']          = false;
204
        $response['message']        = 'Success';
205
        $response['status']         = true;
206
207
        return response()->json($response);
208
    }
209
210
    /**
211
     * Show the form for editing the specified resource.
212
     *
213
     * @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...
214
     * @return \Illuminate\Http\Response
215
     */
216
    public function edit($id)
217
    {
218
        $user_id            = isset(Auth::User()->id) ? Auth::User()->id : null;
219
        $admin_sekolah      = $this->admin_sekolah->with(['sekolah', 'admin_sekolah', 'user'])->findOrFail($id);
220
        $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...
221
        $users_special      = $this->user->all();
222
        $users_standar      = $this->user->findOrFail($user_id);
0 ignored issues
show
Unused Code introduced by
$users_standar 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...
223
        $current_user       = Auth::User();
224
        $admins             = [];
225
226
227
        $role_check = Auth::User()->hasRole(['superadministrator','administrator']);
0 ignored issues
show
Unused Code introduced by
$role_check 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...
228
229
        if ($admin_sekolah->user !== null) {
230
            array_set($admin_sekolah->user, 'label', $admin_sekolah->user->name);
231
        }
232
233
        if ($admin_sekolah->admin_sekolah !== null) {
234
            array_set($admin_sekolah->admin_sekolah, 'label', $admin_sekolah->admin_sekolah->name);
235
        }
236
237 View Code Duplication
        foreach($users_special as $user){
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...
238
            if($user->hasRole(['superadministrator','administrator'])){
239
                array_set($user, 'label', $user->name);
240
                array_push($admins, $user);
241
            }
242
        }
243
244
        array_set($current_user, 'label', $current_user->name);
245
246
        $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...
247
        $response['users']              = $admins;
248
        $response['user_special']       = true;
249
        $response['current_user']       = $current_user;
250
        $response['error']              = false;
251
        $response['message']            = 'Success';
252
        $response['status']             = true;
253
254
        return response()->json($response);
255
    }
256
257
    /**
258
     * Update the specified resource in storage.
259
     *
260
     * @param  \Illuminate\Http\Request  $request
261
     * @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...
262
     * @return \Illuminate\Http\Response
263
     */
264
    public function update(Request $request, $id)
265
    {
266
        if($this->checkRole(['superadministrator'])){
267
            $admin_sekolah = $this->admin_sekolah->with(['sekolah', 'admin_sekolah', 'user'])->findOrFail($id);
268
269
            $validator = Validator::make($request->all(), [
270
                'sekolah_id'            => "required|exists:{$this->sekolah->getTable()},id",
271
                'admin_sekolah_id'      => "required|unique:{$this->admin_sekolah->getTable()},admin_sekolah_id,{$id},id,deleted_at,NULL",
272
            ]);
273
274 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...
275
                $error      = true;
276
                $message    = $validator->errors()->first();
277
            } else {
278
                $admin_sekolah->sekolah_id          = $request->input('sekolah_id');
279
                $admin_sekolah->admin_sekolah_id    = $request->input('admin_sekolah_id');
280
                $admin_sekolah->user_id             = Auth::user()->id;
281
                $admin_sekolah->save();
282
283
                $error      = false;
284
                $message    = 'Success';
285
            }
286
287
            $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...
288
            $response['error']          = $error;
289
            $response['message']        = $message;
290
            $response['status']         = true;
291
292
            return response()->json($response);
293
        }else{
294
            $response['error']          = true;
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...
295
            $response['message']        = 'Maaf anda Tidak mempunyai hak akses untuk ini.';
296
            $response['status']         = true;
297
298
            return response()->json($response);
299
        }
300
301
    }
302
303
    /**
304
     * Remove the specified resource from storage.
305
     *
306
     * @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...
307
     * @return \Illuminate\Http\Response
308
     */
309
    public function destroy($id)
310
    {
311
        if($this->checkRole(['superadministrator'])){
312
            $admin_sekolah = $this->admin_sekolah->findOrFail($id);
313
314
            if ($admin_sekolah->delete()) {
315
                $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...
316
                $response['success']    = true;
317
                $response['status']     = true;
318
            } else {
319
                $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...
320
                $response['success']    = false;
321
                $response['status']     = false;
322
            }
323
324
            return json_encode($response);
325
        }else{
326
            $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...
327
            $response['success']    = false;
328
            $response['status']     = false;
329
            return json_encode($response);
330
        }
331
    }
332
333
    protected function checkRole($role = array())
334
    {
335
        return Auth::user()->hasRole($role);
336
    }
337
}
338