Issues (121)

Security Analysis    no request data  

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

src/Http/Controllers/AdminSekolahController.php (30 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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
    public function index(Request $request)
49
    {
50
        $admin_sekolah = $this->admin_sekolah->where('admin_sekolah_id', Auth::user()->id)->first();
51
52
        if(is_null($admin_sekolah) && $this->checkRole(['superadministrator']) === false){
53
            $response = [];
54
            return response()->json($response)
55
            ->header('Access-Control-Allow-Origin', '*')
56
            ->header('Access-Control-Allow-Methods', 'GET');
57
        }
58
59
        if (request()->has('sort')) {
60
            list($sortCol, $sortDir) = explode('|', request()->sort);
61
62
            if($this->checkRole(['superadministrator'])){
63
                $query = $this->admin_sekolah->orderBy($sortCol, $sortDir);
64
            }else{
65
                $query = $this->admin_sekolah->where('sekolah_id', $admin_sekolah->sekolah_id)->orderBy($sortCol, $sortDir);
66
            }
67
        } else {
68
            if($this->checkRole(['superadministrator'])){
69
                $query = $this->admin_sekolah->orderBy('id', 'asc');
70
            }else{
71
                $query = $this->admin_sekolah->where('admin_sekolah_id', $admin_sekolah->sekolah_id)->orderBy('id', 'asc');
72
            }
73
        }
74
75
        if ($request->exists('filter')) {
76
            if($this->checkRole(['superadministrator'])){
77 View Code Duplication
                $query->where(function($q) use($request) {
0 ignored issues
show
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...
78
                    $value = "%{$request->filter}%";
79
80
                    $q->where('sekolah_id', 'like', $value)
81
                        ->orWhere('admin_sekolah_id', 'like', $value);
82
                });
83
            }else{
84 View Code Duplication
                $query->where(function($q) use($request, $admin_sekolah) {
0 ignored issues
show
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...
85
                    $value = "%{$request->filter}%";
86
87
                    $q->where('sekolah_id', $admin_sekolah->sekolah_id)->where('sekolah_id', 'like', $value);
88
                });
89
            }
90
91
        }
92
93
        $perPage = request()->has('per_page') ? (int) request()->per_page : null;
94
95
        $response = $query->with(['admin_sekolah', 'sekolah', 'user'])->paginate($perPage);
96
97
        return response()->json($response)
98
            ->header('Access-Control-Allow-Origin', '*')
99
            ->header('Access-Control-Allow-Methods', 'GET');
100
101
    }
102
103
    /**
104
     * Display a listing of the resource.
105
     *
106
     * @return \Illuminate\Http\Response
107
     */
108 View Code Duplication
    public function get()
0 ignored issues
show
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...
109
    {
110
        $admin_sekolahs = $this->admin_sekolah->with(['sekolah', 'user'])->get();
111
112
        $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...
113
        $response['error']          = false;
114
        $response['message']        = 'Success';
115
        $response['status']         = true;
116
117
        return response()->json($response);
118
    }
119
120
    /**
121
     * Display a listing of the resource.
122
     *
123
     * @return \Illuminate\Http\Response
124
     */
125 View Code Duplication
    public function getBySekolah($id)
0 ignored issues
show
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...
126
    {
127
        $admin_sekolahs = $this->admin_sekolah->where('sekolah_id', '=', $id)->with(['sekolah', 'user'])->get();
128
129
        $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...
130
        $response['message']        = 'Success';
131
        $response['error']          = false;
132
        $response['status']         = true;
133
134
        return response()->json($response);
135
    }
136
137
    /**
138
     * Show the form for creating a new resource.
139
     *
140
     * @return \Illuminate\Http\Response
141
     */
142
    public function create()
143
    {
144
        $user_id            = isset(Auth::User()->id) ? Auth::User()->id : null;
145
        $admin_sekolah      = $this->admin_sekolah->getAttributes();
146
        $users              = $this->user->getAttributes();
0 ignored issues
show
$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...
147
        $users_special      = $this->user->all();
148
        $users_standar      = $this->user->findOrFail($user_id);
0 ignored issues
show
$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...
149
        $current_user       = Auth::User();
150
        $admins             = [];
151
152
        foreach($users_special as $user){
153
            if($user->hasRole(['superadministrator','admin_sekolah'])){
154
                array_set($user, 'label', $user->name);
155
                array_push($admins, $user);
156
            }
157
        }
158
159
        array_set($current_user, 'label', $current_user->name);
160
161
        $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...
162
        $response['users']              = $admins;
163
        $response['user_special']       = true;
164
        $response['current_user']       = $current_user;
165
        $response['error']              = false;
166
        $response['message']            = 'Success';
167
        $response['status']             = true;
168
169
        return response()->json($response);
170
    }
171
172
    /**
173
     * Store a newly created resource in storage.
174
     *
175
     * @param  \Illuminate\Http\Request  $request
176
     * @return \Illuminate\Http\Response
177
     */
178
    public function store(Request $request)
179
    {
180
        if($this->checkRole(['superadministrator'])){
181
            $admin_sekolah = $this->admin_sekolah;
182
183
            $validator = Validator::make($request->all(), [
184
                'sekolah_id'            => "required|exists:{$this->sekolah->getTable()},id",
185
                'admin_sekolah_id'      => "required|unique:{$this->admin_sekolah->getTable()},admin_sekolah_id,NULL,id,deleted_at,NULL",
186
            ]);
187
188 View Code Duplication
            if ($validator->fails()) {
0 ignored issues
show
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...
189
                $error      = true;
190
                $message    = $validator->errors()->first();
191
            } else {
192
                $admin_sekolah->sekolah_id          = $request->input('sekolah_id');
193
                $admin_sekolah->admin_sekolah_id    = $request->input('admin_sekolah_id');
194
                $admin_sekolah->user_id             = Auth::user()->id;
195
                $admin_sekolah->save();
196
197
                $error      = false;
198
                $message    = 'Success';
199
            }
200
201
            $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...
202
            $response['error']          = $error;
203
            $response['message']        = $message;
204
            $response['status']         = true;
205
206
            return response()->json($response);
207
        }else{
208
209
            $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...
210
            $response['message']        = 'Maaf anda Tidak mempunyai hak akses untuk ini.';
211
            $response['status']         = true;
212
213
            return response()->json($response);
214
        }
215
216
    }
217
218
    /**
219
     * Display the specified resource.
220
     *
221
     * @param  \App\ProdiSekolah  $prodi_sekolah
0 ignored issues
show
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...
222
     * @return \Illuminate\Http\Response
223
     */
224
    public function show($id)
225
    {
226 View Code Duplication
        if($this->checkRole(['superadministrator'])){
0 ignored issues
show
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...
227
            $admin_sekolah = $this->admin_sekolah->with(['sekolah', 'admin_sekolah', 'user'])->findOrFail($id);
228
        }else{
229
            $admin_sekolah = $this->admin_sekolah->where('admin_sekolah_id', Auth::user()->id)->with(['sekolah', 'admin_sekolah', 'user'])->findOrFail($id);
230
        }
231
232
233
        $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...
234
        $response['error']          = false;
235
        $response['message']        = 'Success';
236
        $response['status']         = true;
237
238
        return response()->json($response);
239
    }
240
241
    /**
242
     * Show the form for editing the specified resource.
243
     *
244
     * @param  \App\Sekolah  $sekolah
0 ignored issues
show
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...
245
     * @return \Illuminate\Http\Response
246
     */
247
    public function edit($id)
248
    {
249
        $user_id = isset(Auth::User()->id) ? Auth::User()->id : null;
250
251 View Code Duplication
        if($this->checkRole(['superadministrator'])){
0 ignored issues
show
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...
252
            $admin_sekolah = $this->admin_sekolah->with(['sekolah', 'admin_sekolah', 'user'])->findOrFail($id);
253
        }else{
254
            $admin_sekolah = $this->admin_sekolah->where('admin_sekolah_id', Auth::user()->id)->with(['sekolah', 'admin_sekolah', 'user'])->findOrFail($id);
255
        }
256
257
258
        $users              = $this->user->getAttributes();
0 ignored issues
show
$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...
259
        $users_special      = $this->user->all();
260
        $users_standar      = $this->user->findOrFail($user_id);
0 ignored issues
show
$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...
261
        $current_user       = Auth::User();
262
        $admins             = [];
263
264
265
        $role_check = Auth::User()->hasRole(['superadministrator','administrator']);
0 ignored issues
show
$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...
266
267
        if ($admin_sekolah->user !== null) {
268
            array_set($admin_sekolah->user, 'label', $admin_sekolah->user->name);
269
        }
270
271
        if ($admin_sekolah->admin_sekolah !== null) {
272
            array_set($admin_sekolah->admin_sekolah, 'label', $admin_sekolah->admin_sekolah->name);
273
        }
274
275
        foreach($users_special as $user){
276
            if($user->hasRole(['superadministrator','admin_sekolah'])){
277
                array_set($user, 'label', $user->name);
278
                array_push($admins, $user);
279
            }
280
        }
281
282
        array_set($current_user, 'label', $current_user->name);
283
284
        $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...
285
        $response['users']              = $admins;
286
        $response['user_special']       = true;
287
        $response['current_user']       = $current_user;
288
        $response['error']              = false;
289
        $response['message']            = 'Success';
290
        $response['status']             = true;
291
292
        return response()->json($response);
293
    }
294
295
    /**
296
     * Update the specified resource in storage.
297
     *
298
     * @param  \Illuminate\Http\Request  $request
299
     * @param  \App\Sekolah  $sekolah
0 ignored issues
show
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...
300
     * @return \Illuminate\Http\Response
301
     */
302
    public function update(Request $request, $id)
303
    {
304
        if($this->checkRole(['superadministrator'])){
305
            $admin_sekolah = $this->admin_sekolah->with(['sekolah', 'admin_sekolah', 'user'])->findOrFail($id);
306
307
            $validator = Validator::make($request->all(), [
308
                'sekolah_id'            => "required|exists:{$this->sekolah->getTable()},id",
309
                'admin_sekolah_id'      => "required|unique:{$this->admin_sekolah->getTable()},admin_sekolah_id,{$id},id,deleted_at,NULL",
310
            ]);
311
312 View Code Duplication
            if ($validator->fails()) {
0 ignored issues
show
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...
313
                $error      = true;
314
                $message    = $validator->errors()->first();
315
            } else {
316
                $admin_sekolah->sekolah_id          = $request->input('sekolah_id');
317
                $admin_sekolah->admin_sekolah_id    = $request->input('admin_sekolah_id');
318
                $admin_sekolah->user_id             = Auth::user()->id;
319
                $admin_sekolah->save();
320
321
                $error      = false;
322
                $message    = 'Success';
323
            }
324
325
            $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...
326
            $response['error']          = $error;
327
            $response['message']        = $message;
328
            $response['status']         = true;
329
330
            return response()->json($response);
331
        }else{
332
            $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...
333
            $response['message']        = 'Maaf anda Tidak mempunyai hak akses untuk ini.';
334
            $response['status']         = true;
335
336
            return response()->json($response);
337
        }
338
339
    }
340
341
    /**
342
     * Remove the specified resource from storage.
343
     *
344
     * @param  \App\Sekolah  $sekolah
0 ignored issues
show
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...
345
     * @return \Illuminate\Http\Response
346
     */
347
    public function destroy($id)
348
    {
349
        if($this->checkRole(['superadministrator'])){
350
            $admin_sekolah = $this->admin_sekolah->findOrFail($id);
351
352
            if ($admin_sekolah->delete()) {
353
                $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...
354
                $response['success']    = true;
355
                $response['status']     = true;
356
            } else {
357
                $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...
358
                $response['success']    = false;
359
                $response['status']     = false;
360
            }
361
362
            return json_encode($response);
363
        }else{
364
            $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...
365
            $response['success']    = false;
366
            $response['status']     = false;
367
            return json_encode($response);
368
        }
369
    }
370
371
    protected function checkRole($role = array())
372
    {
373
        return Auth::user()->hasRole($role);
374
    }
375
}
376