Issues (122)

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