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/MasterPrestasiController.php (22 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\MasterPrestasi;
13
use Bantenprov\Prestasi\Models\Bantenprov\Prestasi\JenisPrestasi;
14
use App\User;
15
16
/* Etc */
17
use Validator;
18
use Auth;
19
20
/**
21
 * The PrestasiController class.
22
 *
23
 * @package Bantenprov\Prestasi
24
 * @author  bantenprov <[email protected]>
25
 */
26
class MasterPrestasiController extends Controller
27
{
28
    /**
29
     * Create a new controller instance.
30
     *
31
     * @return void
32
     */
33
    protected $master_prestasi;
34
    protected $jenis_prestasi;
35
    protected $user;
36
37
    public function __construct()
38
    {
39
        $this->master_prestasi  = new MasterPrestasi;
40
        $this->jenis_prestasi   = new JenisPrestasi;
41
        $this->user             = new User;
42
    }
43
44
    /**
45
     * Display a listing of the resource.
46
     *
47
     * @return \Illuminate\Http\Response
48
     */
49 View Code Duplication
    public function index(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...
50
    {
51
        if (request()->has('sort')) {
52
            list($sortCol, $sortDir) = explode('|', request()->sort);
53
54
            $query = $this->master_prestasi->orderBy($sortCol, $sortDir);
55
        } else {
56
            $query = $this->master_prestasi->orderBy('id', 'asc');
57
        }
58
59
        if ($request->exists('filter')) {
60
            $query->where(function($q) use($request) {
61
                $value = "%{$request->filter}%";
62
                $q->where('nilai', 'like', $value)
63
                    ->orWhere('id', 'like', $value);
64
            });
65
        }
66
67
        $perPage = request()->has('per_page') ? (int) request()->per_page : null;
68
        $response = $query->with('user')->with('jenis_prestasi')->paginate($perPage);
69
70
71
        return response()->json($response)
72
            ->header('Access-Control-Allow-Origin', '*')
73
            ->header('Access-Control-Allow-Methods', 'GET');
74
    }
75
76
    /**
77
     * Show the form for creating a new resource.
78
     *
79
     * @return \Illuminate\Http\Response
80
     */
81
82
    public function create()
83
    {
84
        $response = [];
85
86
        $jenis_prestasis = $this->jenis_prestasi->all();
87
        $users_special = $this->user->all();
88
        $users_standar = $this->user->find(\Auth::User()->id);
89
        $current_user = \Auth::User();
90
91
        $role_check = \Auth::User()->hasRole(['superadministrator','administrator']);
92
93 View Code Duplication
        if($role_check){
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...
94
            $response['user_special'] = true;
95
            foreach($users_special as $user){
96
                array_set($user, 'label', $user->name);
97
            }
98
            $response['user'] = $users_special;
99
        }else{
100
            $response['user_special'] = false;
101
            array_set($users_standar, 'label', $users_standar->name);
102
            $response['user'] = $users_standar;
103
        }
104
105
        array_set($current_user, 'label', $current_user->name);
106
107
        $response['current_user'] = $current_user;
108
109
        foreach($jenis_prestasis as $jenis_prestasi){
110
            array_set($jenis_prestasi, 'label', $jenis_prestasi->nama);
111
        }
112
113
        $response['jenis_prestasi'] = $jenis_prestasis;
114
        $response['status'] = true;
115
116
        return response()->json($response);
117
    }
118
119
    /**
120
     * Display the specified resource.
121
     *
122
     * @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...
123
     * @return \Illuminate\Http\Response
124
     */
125
    public function store(Request $request)
126
    {
127
        $master_prestasi = $this->master_prestasi;
128
129
        $validator = Validator::make($request->all(), [
130
            /*'user_id' => 'required|unique:master_prestasis,user_id',*/
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...
131
            'user_id' => 'required',
132
            'jenis_prestasi_id' => 'required',
133
            'juara' => 'required',
134
            'kode' => 'required|unique:master_prestasis,kode',
135
            'tingkat' => 'required',
136
            'nilai' => 'required'
137
        ]);
138
139
        if($validator->fails()){
140
            $check = $master_prestasi->where('kode',$request->kode)->whereNull('deleted_at')->count();
141
142 View Code Duplication
            if ($check > 0) {
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...
143
                $response['message'] = 'Failed ! Kode Prestasi, already exists';
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...
144
            } else {
145
                $master_prestasi->jenis_prestasi_id = $request->input('jenis_prestasi_id');
146
                $master_prestasi->user_id = $request->input('user_id');
147
                $master_prestasi->juara = $request->input('juara');
148
                $master_prestasi->kode = $request->input('kode');
149
                $master_prestasi->tingkat = $request->input('tingkat');
150
                $master_prestasi->nilai = $request->input('nilai');
151
                $master_prestasi->save();
152
153
                $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...
154
            }
155
        } else {
156
                $master_prestasi->jenis_prestasi_id = $request->input('jenis_prestasi_id');
157
                $master_prestasi->user_id = $request->input('user_id');
158
                $master_prestasi->juara = $request->input('juara');
159
                $master_prestasi->kode = $request->input('kode');
160
                $master_prestasi->tingkat = $request->input('tingkat');
161
                $master_prestasi->nilai = $request->input('nilai');
162
                $master_prestasi->save();
163
164
            $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...
165
        }
166
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
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...
176
     * @return \Illuminate\Http\Response
177
     */
178 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...
179
    {
180
        $master_prestasi = $this->master_prestasi->findOrFail($id);
181
182
        $response['user'] = $master_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...
183
        $response['jenis_prestasi'] = $master_prestasi->jenis_prestasi;
184
        $response['master_prestasi'] = $master_prestasi;
185
        $response['status'] = true;
186
187
        return response()->json($response);
188
    }
189
190
    /**
191
     * Show the form for editing the specified resource.
192
     *
193
     * @param  \App\Prestasi  $prestasi
194
     * @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...
195
     */
196
197
    public function edit($id)
198
    {
199
        $master_prestasi = $this->master_prestasi->findOrFail($id);
200
201
        array_set($master_prestasi->user, 'label', $master_prestasi->user->name);
202
        array_set($master_prestasi->jenis_prestasi, 'label', $master_prestasi->jenis_prestasi->nama);
203
204
        $response['master_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...
205
        $response['jenis_prestasi'] = $master_prestasi->jenis_prestasi;
206
        $response['user'] = $master_prestasi->user;
207
        $response['status'] = true;
208
209
        return response()->json($response);
210
    }
211
212
    /**
213
     * Update the specified resource in storage.
214
     *
215
     * @param  \Illuminate\Http\Request  $request
216
     * @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...
217
     * @return \Illuminate\Http\Response
218
     */
219
    public function update(Request $request, $id)
220
    {
221
        $response = array();
222
        $message  = array();
223
        $master_prestasi = $this->master_prestasi->findOrFail($id);
224
225
            $validator = Validator::make($request->all(), [
226
                /*'user_id' => 'required|unique:sktms,user_id,'.$id,*/
0 ignored issues
show
Unused Code Comprehensibility introduced by
63% of this comment could be valid code. Did you maybe forget this after debugging?

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

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

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

Loading history...
227
                'user_id' => 'required',
228
                'jenis_prestasi_id' => 'required',
229
                'juara' => 'required',
230
                'kode' => 'required|unique:master_prestasis,kode',
231
                'tingkat' => 'required',
232
                'nilai' => 'required'
233
234
            ]);
235
236
        if ($validator->fails()) {
237
238
            foreach($validator->messages()->getMessages() as $key => $error){
239
                        foreach($error AS $error_get) {
240
                            array_push($message, $error_get);
241
                        }
242
                    }
243
244
            $check_kode = $this->master_prestasi->where('id','!=', $id)->where('kode', $request->kode);
245
246 View Code Duplication
             if($check_kode->count() > 0){
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...
247
                  $response['message'] = implode("\n",$message);
248
249
            } else {
250
                $master_prestasi->user_id = $request->input('user_id');
251
                $master_prestasi->jenis_prestasi_id = $request->input('jenis_prestasi_id');
252
                $master_prestasi->juara = $request->input('juara');
253
                $master_prestasi->kode = $request->input('kode');
254
                $master_prestasi->tingkat = $request->input('tingkat');
255
                $master_prestasi->nilai = $request->input('nilai');
256
                $master_prestasi->save();
257
258
                $response['message'] = 'success';
259
            }
260
        } else {
261
                $master_prestasi->user_id = $request->input('user_id');
262
                $master_prestasi->jenis_prestasi_id = $request->input('jenis_prestasi_id');
263
                $master_prestasi->juara = $request->input('juara');
264
                $master_prestasi->kode = $request->input('kode');
265
                $master_prestasi->tingkat = $request->input('tingkat');
266
                $master_prestasi->nilai = $request->input('nilai');
267
                $master_prestasi->save();
268
269
            $response['message'] = 'success';
270
        }
271
272
        $response['status'] = true;
273
274
        return response()->json($response);
275
    }
276
277
    /**
278
     * Remove the specified resource from storage.
279
     *
280
     * @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...
281
     * @return \Illuminate\Http\Response
282
     */
283 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...
284
    {
285
        $master_prestasi = $this->master_prestasi->findOrFail($id);
286
287
        if ($master_prestasi->delete()) {
288
            $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...
289
        } else {
290
            $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...
291
        }
292
        return json_encode($response);
293
    }
294
295 View Code Duplication
    public function juara(){
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...
296
        return json_encode(array(
297
            array('id' => 1, 'label' => 'Juara 1'),
298
            array('id' => 2, 'label' => 'Juara 2'),
299
            array('id' => 3, 'label' => 'Juara 3'),
300
            array('id' => 4, 'label' => 'Juara Harapan 1'),
301
        ));            
302
    }
303
304
    public function juara_label($id){
305
        $juaras     = json_decode($this->juara(),true);
306
        foreach($juaras as $key => $val){
307
            if($val['id'] == $id){
308
                return $val['label'];
309
            }else{
310
                return NULL;
311
            }    
312
        }
313
    }
314
    
315 View Code Duplication
    public function tingkat(){
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...
316
        return json_encode(array(
317
            array('id' => 1, 'label' => 'Tingkat Internasional'),
318
            array('id' => 2, 'label' => 'Tingkat Nasional'),
319
            array('id' => 3, 'label' => 'Tingkat Provinsi'),
320
            array('id' => 4, 'label' => 'Tingkat Kabupaten/Kota')
321
        ));
322
    }
323
324
    public function tingkat_label($id){
325
        $tingkats   = json_decode($this->tingkat(),true);
326
        foreach($tingkats as $key => $val){
327
            if($val['id'] == $id){
328
                return $val['label'];
329
            }else{
330
                return NULL;
331
            }    
332
        }
333
    }
334
    
335
}
336