Issues (63)

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/SktmController.php (25 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\Sktm\Http\Controllers;
4
5
/* Require */
6
use App\Http\Controllers\Controller;
7
use Illuminate\Http\Request;
8
use Illuminate\Support\Facades\DB;
9
use Bantenprov\Sktm\Facades\SktmFacade;
10
11
/* Models */
12
use Bantenprov\Sktm\Models\Bantenprov\Sktm\Sktm;
13
use Bantenprov\Siswa\Models\Bantenprov\Siswa\Siswa;
14
use Bantenprov\Sktm\Models\Bantenprov\Sktm\MasterSktm;
15
use App\User;
16
use Bantenprov\Nilai\Models\Bantenprov\Nilai\Nilai;
17
use Bantenprov\Sekolah\Models\Bantenprov\Sekolah\AdminSekolah;
18
19
/* Etc */
20
use Validator;
21
use Auth;
22
23
/**
24
 * The SktmController class.
25
 *
26
 * @package Bantenprov\Sktm
27
 * @author  bantenprov <[email protected]>
28
 */
29
class SktmController extends Controller
30
{
31
    protected $sktm;
32
    protected $siswa;
33
    protected $master_sktm;
34
    protected $user;
35
    protected $nilai;
36
    protected $admin_sekolah;
37
38
    /**
39
     * Create a new controller instance.
40
     *
41
     * @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...
42
     */
43
    public function __construct()
44
    {
45
        $this->sktm             = new Sktm;
46
        $this->siswa            = new Siswa;
47
        $this->master_sktm      = new MasterSktm;
48
        $this->user             = new User;
49
        $this->nilai            = new Nilai;
50
        $this->admin_sekolah    = new AdminSekolah;
51
    }
52
53
    /**
54
     * Display a listing of the resource.
55
     *
56
     * @return \Illuminate\Http\Response
57
     */
58
    public function index(Request $request)
59
    {
60
        $admin_sekolah = $this->admin_sekolah->where('admin_sekolah_id', Auth::user()->id)->first();
61
62
        if(is_null($admin_sekolah) && $this->checkRole(['superadministrator']) === false){
63
            $response = [];
64
            return response()->json($response)
65
            ->header('Access-Control-Allow-Origin', '*')
66
            ->header('Access-Control-Allow-Methods', 'GET');
67
        }
68
69
        if (request()->has('sort')) {
70
            list($sortCol, $sortDir) = explode('|', request()->sort);
71
72
            if($this->checkRole(['superadministrator'])){
73
                $query = $this->sktm->orderBy($sortCol, $sortDir);
74
            }else{
75
                $query = $this->sktm->where('user_id', $admin_sekolah->admin_sekolah_id)->orderBy($sortCol, $sortDir);
76
            }
77
        } else {
78
            if($this->checkRole(['superadministrator'])){
79
                $query = $this->sktm->orderBy('id', 'asc');
80
            }else{
81
                $query = $this->sktm->where('user_id', $admin_sekolah->admin_sekolah_id)->orderBy('id', 'asc');
82
            }
83
        }
84
85
        if ($request->exists('filter')) {
86
            if($this->checkRole(['superadministrator'])){
87 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...
88
                    $value = "%{$request->filter}%";
89
90
                    $q->where('sekolah_id', 'like', $value)
91
                        ->orWhere('admin_sekolah_id', 'like', $value);
92
                });
93
            }else{
94 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...
95
                    $value = "%{$request->filter}%";
96
97
                    $q->where('sekolah_id', $admin_sekolah->sekolah_id)->where('sekolah_id', 'like', $value);
98
                });
99
            }
100
101
        }
102
103
104
        $perPage    = request()->has('per_page') ? (int) request()->per_page : null;
105
106
        $response   = $query->with(['siswa', 'master_sktm', 'user'])->paginate($perPage);
107
108
        return response()->json($response)
109
            ->header('Access-Control-Allow-Origin', '*')
110
            ->header('Access-Control-Allow-Methods', 'GET');
111
    }
112
113
    /**
114
     * Display a listing of the resource.
115
     *
116
     * @return \Illuminate\Http\Response
117
     */
118
    public function get()
119
    {
120
        $sktms = $this->sktm->with(['master_sktm', 'user'])->get();
121
122
        $response['sktms']      = $sktms;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$response was never initialized. Although not strictly required by PHP, it is generally a good practice to add $response = array(); before regardless.

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

Let’s take a look at an example:

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

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

    // do something with $myArray
}

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

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

Loading history...
123
        $response['error']      = false;
124
        $response['message']    = 'Success';
125
        $response['status']     = true;
126
127
        return response()->json($response);
128
    }
129
130
    /**
131
     * Show the form for creating a new resource.
132
     *
133
     * @return \Illuminate\Http\Response
134
     */
135
    public function create()
136
    {
137
        $user_id        = isset(Auth::User()->id) ? Auth::User()->id : null;
138
        $sktm           = $this->sktm->getAttributes();
139
        $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...
140
        $users_special  = $this->user->all();
141
        $users_standar  = $this->user->findOrFail($user_id);
142
        $current_user   = Auth::User();
143
144
        $admin_sekolah = $this->admin_sekolah->where('admin_sekolah_id', Auth::user()->id)->first();
145
146
        if($this->checkRole(['superadministrator'])){
147
            $siswas = $this->siswa->all();
148
        }else{
149
            $sekolah_id = $admin_sekolah->sekolah_id;
150
            $siswas     = $this->siswa->where('sekolah_id', $sekolah_id)->get();
151
        }
152
153
     //   dd($siswas);
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...
154
155
        $role_check = Auth::User()->hasRole(['superadministrator','administrator']);
156
157
        if ($role_check) {
158
            $user_special = true;
159
160
            foreach ($users_special as $user) {
161
                array_set($user, 'label', $user->name);
162
            }
163
164
            $users = $users_special;
165
        } else {
166
            $user_special = false;
167
168
            array_set($users_standar, 'label', $users_standar->name);
169
170
            $users = $users_standar;
171
        }
172
173
        array_set($current_user, 'label', $current_user->name);
174
175
        $response['sktm']           = $sktm;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$response was never initialized. Although not strictly required by PHP, it is generally a good practice to add $response = array(); before regardless.

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

Let’s take a look at an example:

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

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

    // do something with $myArray
}

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

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

Loading history...
176
        $response['siswa']          = $siswas;
177
        $response['users']          = $users;
178
        $response['user_special']   = $user_special;
179
        $response['current_user']   = $current_user;
180
        $response['error']          = false;
181
        $response['message']        = 'Success';
182
        $response['status']         = true;
183
184
        return response()->json($response);
185
    }
186
187
    /**
188
     * Store a newly created resource in storage.
189
     *
190
     * @param  \Illuminate\Http\Request  $request
191
     * @return \Illuminate\Http\Response
192
     */
193
    public function store(Request $request)
194
    {
195
        $sktm = $this->sktm;
196
197
        $validator = Validator::make($request->all(), [
198
            'nomor_un'          => "required|exists:{$this->siswa->getTable()},nomor_un|unique:{$this->sktm->getTable()},nomor_un,NULL,id,deleted_at,NULL",
199
            'master_sktm_id'    => "required|exists:{$this->master_sktm->getTable()},id",
200
            'no_sktm'           => 'required|max:255',
201
            // 'nilai'             => 'required|numeric|min:0|max:100',
0 ignored issues
show
Unused Code Comprehensibility introduced by
58% of this comment could be valid code. Did you maybe forget this after debugging?

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

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

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

Loading history...
202
            'user_id'           => "required|exists:{$this->user->getTable()},id",
203
        ]);
204
205 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...
206
            $error      = true;
207
            $message    = $validator->errors()->first();
208
        } else {
209
            $sktm_master_sktm_id    = $request->input('master_sktm_id');
210
            $master_sktm            = $this->master_sktm->findOrFail($sktm_master_sktm_id);
211
212
            $sktm->nomor_un         = $request->input('nomor_un');
213
            $sktm->master_sktm_id   = $sktm_master_sktm_id;
214
            $sktm->no_sktm          = $request->input('no_sktm');
215
            $sktm->nilai            = $master_sktm->nilai;
216
            $sktm->user_id          = $request->input('user_id');
217
218
            $nilai = $this->nilai->updateOrCreate(
219
                [
220
                    'nomor_un'  => $sktm->nomor_un,
221
                ],
222
                [
223
                    'sktm'          => $sktm->nilai,
224
                    'kegiatan_id'   => null,
225
                    'total'         => null,
226
                    'user_id'       => $sktm->user_id,
227
                ]
228
            );
229
230
            DB::beginTransaction();
231
232
            if ($sktm->save() && $nilai->save())
233
            {
234
                DB::commit();
235
236
                $error      = false;
237
                $message    = 'Success';
238
            } else {
239
                DB::rollBack();
240
241
                $error      = true;
242
                $message    = 'Failed';
243
            }
244
        }
245
246
        $response['sktm']       = $sktm;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$response was never initialized. Although not strictly required by PHP, it is generally a good practice to add $response = array(); before regardless.

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

Let’s take a look at an example:

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

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

    // do something with $myArray
}

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

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

Loading history...
247
        $response['error']      = $error;
248
        $response['message']    = $message;
249
        $response['status']     = true;
250
251
        return response()->json($response);
252
    }
253
254
    /**
255
     * Display the specified resource.
256
     *
257
     * @param  \App\Sktm  $nilai
0 ignored issues
show
There is no parameter named $nilai. Was it maybe removed?

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

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

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

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

Loading history...
258
     * @return \Illuminate\Http\Response
259
     */
260 View Code Duplication
    public function show($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...
261
    {
262
        $sktm = $this->sktm->with(['siswa', 'master_sktm', 'user'])->findOrFail($id);
263
264
        $response['sktm']       = $sktm;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$response was never initialized. Although not strictly required by PHP, it is generally a good practice to add $response = array(); before regardless.

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

Let’s take a look at an example:

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

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

    // do something with $myArray
}

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

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

Loading history...
265
        $response['error']      = false;
266
        $response['message']    = 'Success';
267
        $response['status']     = true;
268
269
        return response()->json($response);
270
    }
271
272
    /**
273
     * Show the form for editing the specified resource.
274
     *
275
     * @param  \App\Sktm  $nilai
0 ignored issues
show
There is no parameter named $nilai. Was it maybe removed?

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

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

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

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

Loading history...
276
     * @return \Illuminate\Http\Response
277
     */
278 View Code Duplication
    public function edit($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...
279
    {
280
        $user_id        = isset(Auth::User()->id) ? Auth::User()->id : null;
281
        $sktm           = $this->sktm->with(['siswa', 'master_sktm', 'user'])->findOrFail($id);
282
        $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...
283
        $users_special  = $this->user->all();
284
        $users_standar  = $this->user->findOrFail($user_id);
285
        $current_user   = Auth::User();
286
287
        if ($sktm->user !== null) {
288
            array_set($sktm->user, 'label', $sktm->user->name);
289
        }
290
291
        $role_check = Auth::User()->hasRole(['superadministrator','administrator']);
292
293
        if ($role_check) {
294
            $user_special = true;
295
296
            foreach ($users_special as $user) {
297
                array_set($user, 'label', $user->name);
298
            }
299
300
            $users = $users_special;
301
        } else {
302
            $user_special = false;
303
304
            array_set($users_standar, 'label', $users_standar->name);
305
306
            $users = $users_standar;
307
        }
308
309
        array_set($current_user, 'label', $current_user->name);
310
311
        $response['sktm']           = $sktm;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$response was never initialized. Although not strictly required by PHP, it is generally a good practice to add $response = array(); before regardless.

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

Let’s take a look at an example:

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

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

    // do something with $myArray
}

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

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

Loading history...
312
        $response['users']          = $users;
313
        $response['user_special']   = $user_special;
314
        $response['current_user']   = $current_user;
315
        $response['error']          = false;
316
        $response['message']        = 'Success';
317
        $response['status']         = true;
318
319
        return response()->json($response);
320
    }
321
322
    /**
323
     * Update the specified resource in storage.
324
     *
325
     * @param  \Illuminate\Http\Request  $request
326
     * @param  \App\Sktm  $nilai
0 ignored issues
show
There is no parameter named $nilai. Was it maybe removed?

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

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

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

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

Loading history...
327
     * @return \Illuminate\Http\Response
328
     */
329
    public function update(Request $request, $id)
330
    {
331
        $sktm = $this->sktm->with(['siswa', 'master_sktm', 'user'])->findOrFail($id);
332
333
        $validator = Validator::make($request->all(), [
334
            // 'nomor_un'          => "required|exists:{$this->siswa->getTable()},nomor_un|unique:{$this->sktm->getTable()},nomor_un,{$id},id,deleted_at,NULL",
0 ignored issues
show
Unused Code Comprehensibility introduced by
58% of this comment could be valid code. Did you maybe forget this after debugging?

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

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

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

Loading history...
335
            'master_sktm_id'    => "required|exists:{$this->master_sktm->getTable()},id",
336
            'no_sktm'           => 'required|max:255',
337
            // 'nilai'             => 'required|numeric|min:0|max:100',
0 ignored issues
show
Unused Code Comprehensibility introduced by
58% of this comment could be valid code. Did you maybe forget this after debugging?

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

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

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

Loading history...
338
            'user_id'           => "required|exists:{$this->user->getTable()},id",
339
        ]);
340
341 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...
342
            $error      = true;
343
            $message    = $validator->errors()->first();
344
        } else {
345
            $sktm_master_sktm_id    = $request->input('master_sktm_id');
346
            $master_sktm            = $this->master_sktm->findOrFail($sktm_master_sktm_id);
347
348
            $sktm->nomor_un         = $request->input('nomor_un');
349
            $sktm->master_sktm_id   = $sktm_master_sktm_id;
350
            $sktm->no_sktm          = $request->input('no_sktm');
351
            $sktm->nilai            = $master_sktm->nilai;
352
            $sktm->user_id          = $request->input('user_id');
353
354
            $nilai = $this->nilai->updateOrCreate(
355
                [
356
                    'nomor_un'  => $sktm->nomor_un,
357
                ],
358
                [
359
                    'sktm'      => $sktm->nilai,
360
                    'kegiatan_id'   => null,
361
                    'total'     => null,
362
                    'user_id'   => $sktm->user_id,
363
                ]
364
            );
365
366
            DB::beginTransaction();
367
368
            if ($sktm->save() && $nilai->save())
369
            {
370
                DB::commit();
371
372
                $error      = false;
373
                $message    = 'Success';
374
            } else {
375
                DB::rollBack();
376
377
                $error      = true;
378
                $message    = 'Failed';
379
            }
380
        }
381
382
        $response['sktm']       = $sktm;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$response was never initialized. Although not strictly required by PHP, it is generally a good practice to add $response = array(); before regardless.

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

Let’s take a look at an example:

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

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

    // do something with $myArray
}

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

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

Loading history...
383
        $response['error']      = $error;
384
        $response['message']    = $message;
385
        $response['status']     = true;
386
387
        return response()->json($response);
388
    }
389
390
    /**
391
     * Remove the specified resource from storage.
392
     *
393
     * @param  \App\Sktm  $nilai
0 ignored issues
show
There is no parameter named $nilai. Was it maybe removed?

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

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

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

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

Loading history...
394
     * @return \Illuminate\Http\Response
395
     */
396
    public function destroy($id)
397
    {
398
        $sktm = $this->sktm->findOrFail($id);
399
400
        $nilai = $this->nilai->updateOrCreate(
401
            [
402
                'nomor_un'  => $sktm->nomor_un,
403
            ],
404
            [
405
                'sktm'      => 0,
406
                'total'     => null,
407
                'user_id'   => $sktm->user_id,
408
            ]
409
        );
410
411
        DB::beginTransaction();
412
413
        if ($sktm->delete() && $nilai->save())
414
        {
415
            DB::commit();
416
417
            $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...
418
            $response['success']    = true;
419
        } else {
420
            DB::rollBack();
421
422
            $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...
423
            $response['success']    = false;
424
        }
425
426
        $response['status']     = true;
427
428
        return json_encode($response);
429
    }
430
431
    protected function checkRole($role = array())
432
    {
433
        return Auth::user()->hasRole($role);
434
    }
435
}
436