Issues (35)

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/DataAkademikController.php (28 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\DataAkademik\Http\Controllers;
4
5
/* Require */
6
use App\Http\Controllers\Controller;
7
use Illuminate\Http\Request;
8
use Bantenprov\DataAkademik\Facades\DataAkademikFacade;
9
use Bantenprov\Sekolah\Models\Bantenprov\Sekolah\AdminSekolah;
10
use App\User;
11
12
/* Models */
13
use Bantenprov\DataAkademik\Models\Bantenprov\DataAkademik\DataAkademik;
14
15
/* Etc */
16
use Validator;
17
use Auth;
18
19
/**
20
 * The DataAkademikController class.
21
 *
22
 * @package Bantenprov\DataAkademik
23
 * @author  bantenprov <[email protected]>
24
 */
25
class DataAkademikController extends Controller
26
{
27
    /**
28
     * Create a new controller instance.
29
     *
30
     * @return void
31
     */
32
    protected $user;
33
    public function __construct(DataAkademik $data_akademik, User $user)
34
    {
35
        $this->data_akademik    = $data_akademik;
36
        $this->user             = $user;
37
    }
38
39
    /**
40
     * Display a listing of the resource.
41
     *
42
     * @return \Illuminate\Http\Response
43
     */
44
    public function index(Request $request)
45
    {
46
        if ($request->has('sort')) {
47
            list($sortCol, $sortDir) = explode('|', $request->sort);
48
49
            $query = $this->data_akademik->with('user')->orderBy($sortCol, $sortDir);
50
        } else {
51
            $query = $this->data_akademik->with('user')->orderBy('id', 'asc');
52
        }
53
54
        if ($request->exists('filter')) {
55
            $query->where(function($q) use($request) {
56
                $value = "%{$request->filter}%";
57
                $q->where('nama_siswa', 'like', $value)
58
                    ->orWhere('nomor_un', 'like', $value);
59
            });
60
        }
61
62
63
        $perPage = $request->has('per_page') ? (int) $request->per_page : null;
64
65
        if($this->checkRole(['superadministrator','administrator'])){
66
            $response = $query->paginate($perPage);
67
        }else{
68
            $response = [];
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
    public function create()
82
    {
83
        $response = [];
84
85
        $users_special = $this->user->all();
86
        $users_standar = $this->user->find(\Auth::User()->id);
87
        $current_user = \Auth::User();
88
89
        $role_check = \Auth::User()->hasRole(['superadministrator']);
90
91
        if($role_check){
92
            $response['user_special'] = true;
93
            foreach($users_special as $user){
94
                array_set($user, 'label', $user->name);
95
            }
96
            $response['user'] = $users_special;
97
        }else{
98
            $response['user_special'] = false;
99
            array_set($users_standar, 'label', $users_standar->name);
100
            if($this->checkRole(['superadministrator','administrator'])){
101
                $response['user'] = $users_standar;
102
            }else{
103
                $response['user'] = null;
104
            }
105
        }
106
107
        array_set($current_user, 'label', $current_user->name);
108
109 View Code Duplication
        if($this->checkRole(['superadministrator','administrator'])){
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...
110
            $response['current_user']   = $current_user;
111
            $response['status']         = true;
112
            $response['error']          = false;
113
        }else{
114
            $response['current_user']   = null;
115
            $response['status']         = null;
116
            $response['error']          = true;
117
            $response['message']        = 'Anda Tidak mempunyai hak akses';            
118
        }
119
120
        $response['status']         = true;
121
122
        return response()->json($response);
123
    }
124
125
    /**
126
     * Display the specified resource.
127
     *
128
     * @param  \App\DataAkademik  $data_akademik
0 ignored issues
show
There is no parameter named $data_akademik. 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...
129
     * @return \Illuminate\Http\Response
130
     */
131
    public function store(Request $request)
132
    {
133
        if($this->checkRole(['superadministrator','administrator'])){
134
            
135
            $data_akademik = $this->data_akademik;
136
137
            $validator = Validator::make($request->all(), [
138
                'nomor_un'          => 'required|unique:data_akademiks,nomor_un',
139
                'nama_siswa'        => 'required',
140
                'nomor_kk'          => 'max:255',
141
                'tanggal_lahir'     => 'required|date',
142
                'bahasa_indonesia'  => 'required|numeric',
143
                'bahasa_inggris'    => 'required|numeric',
144
                'matematika'        => 'required|numeric',
145
                'ipa'               => 'required|numeric',
146
                'user_id'           => 'required',
147
            ]);
148
149
        if($validator->fails()){
150
            $check = $data_akademik->where('nomor_un',$request->nomor_un)->whereNull('deleted_at')->count();
151
152
            if ($check > 0) {
153
                $response['message'] = 'Failed Nomor UN : ' . $request->nomor_un . ' 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...
154
155 View Code Duplication
            } else {
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...
156
                $data_akademik->nomor_un          = $request->input('nomor_un');
157
                $data_akademik->nama_siswa        = $request->input('nama_siswa');
158
                $data_akademik->nomor_kk          = $request->input('nomor_kk');
159
                $data_akademik->tanggal_lahir     = $request->input('tanggal_lahir');
160
                $data_akademik->user_id           = $request->input('user_id');
161
                $data_akademik->bahasa_indonesia  = $request->input('bahasa_indonesia');
162
                $data_akademik->bahasa_inggris    = $request->input('bahasa_inggris');
163
                $data_akademik->matematika        = $request->input('matematika');
164
                $data_akademik->ipa               = $request->input('ipa');
165
                $data_akademik->save();
166
            }
167 View Code Duplication
        } else {
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...
168
            $data_akademik->nomor_un          = $request->input('nomor_un');
169
            $data_akademik->nama_siswa        = $request->input('nama_siswa');
170
            $data_akademik->nomor_kk          = $request->input('nomor_kk');
171
            $data_akademik->tanggal_lahir     = $request->input('tanggal_lahir');
172
            $data_akademik->user_id           = $request->input('user_id');
173
            $data_akademik->bahasa_indonesia  = $request->input('bahasa_indonesia');
174
            $data_akademik->bahasa_inggris    = $request->input('bahasa_inggris');
175
            $data_akademik->matematika        = $request->input('matematika');
176
            $data_akademik->ipa               = $request->input('ipa');
177
            $data_akademik->save();
178
179
        }
180
181
        $response['status']         = true;
0 ignored issues
show
The variable $response does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
182
        $response['error']          = false;
183
        $response['message']        = 'Success';
184
185
        return response()->json($response);
186
187 View Code Duplication
        }else{
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...
188
            $response['message'] = 'Tidak mempunyai hak ases untuk ini.';
189
            $response['status']  = true;
190
191
            return response()->json($response);
192
193
        }
194
        
195
    }
196
197
    /**
198
     * Store a newly created resource in storage.
199
     *
200
     * @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...
201
     * @return \Illuminate\Http\Response
202
     */
203
    public function show($id)
204
    {
205
206
207
        $data_akademik = $this->data_akademik->findOrFail($id);
208
209
        array_set($data_akademik, 'user', $data_akademik->user->name);
210
211
        if($this->checkRole(['superadministrator','administrator'])){
212
            $response['data_akademik']      = $data_akademik;
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...
213
            $response['status']             = true;
214
        }else{
215
            $response['data_akademik']      = [];
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...
216
            $response['massege']            = 'Tidak mempunyai hak akses untuk ini.';
217
            $response['status']             = true;
218
        }
219
220
221
        return response()->json($response);
222
    }
223
224
    /**
225
     * Show the form for editing the specified resource.
226
     *
227
     * @param  \App\DataAkademik  $data_akademik
0 ignored issues
show
There is no parameter named $data_akademik. 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...
228
     * @return \Illuminate\Http\Response
229
     */
230
    public function edit($id)
231
    {
232
        $data_akademik = $this->data_akademik->findOrFail($id);
233
234
        array_set($data_akademik->user, 'label', $data_akademik->user->name);
235
236 View Code Duplication
        if($this->checkRole(['superadministrator'])){
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
237
            $response['data_akademik']      = $data_akademik;
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...
238
            $response['user']               = $data_akademik->user;
239
            $response['status']             = true;
240
        }else{
241
            $response['message']            = 'Tidak mempunyai hak akses untuk ini.';
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...
242
            $response['data_akademik']      = null;
243
            $response['user']               = null;
244
            $response['status']             = true;
245
        }
246
247
248
249
        return response()->json($response);
250
    }
251
252
    /**
253
     * Update the specified resource in storage.
254
     *
255
     * @param  \Illuminate\Http\Request  $request
256
     * @param  \App\DataAkademik  $data_akademik
0 ignored issues
show
There is no parameter named $data_akademik. 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...
257
     * @return \Illuminate\Http\Response
258
     */
259
    public function update(Request $request, $id)
260
    {
261
        if($this->checkRole(['superadministrator'])){
262
263
        $data_akademik = $this->data_akademik->findOrFail($id);
264
265
        if ($request->input('old_nomor_un') == $request->input('nomor_un'))
266
        {
267
            $validator = Validator::make($request->all(), [
268
                'nomor_un'          => 'required',
269
                'nama_siswa'        => 'required',
270
                'nomor_kk'          => 'required',
271
                'tanggal_lahir'     => 'required|date',
272
                'bahasa_indonesia'  => 'required|numeric',
273
                'bahasa_inggris'    => 'required|numeric',
274
                'matematika'        => 'required|numeric',
275
                'ipa'               => 'required|numeric',
276
                'user_id'           => 'required',
277
278
            ]);
279
        } else {
280
            $validator = Validator::make($request->all(), [
281
                'nomor_un'          => 'required|unique:data_akademiks,nomor_un',
282
                'nama_siswa'        => 'required',
283
                'nomor_kk'          => 'max:255',
284
                'tanggal_lahir'     => 'required|date',
285
                'bahasa_indonesia'  => 'required|numeric',
286
                'bahasa_inggris'    => 'required|numeric',
287
                'matematika'        => 'required|numeric',
288
                'ipa'               => 'required|numeric',
289
                'user_id'           => 'required',
290
            ]);
291
        }
292
293
        if ($validator->fails()) {
294
            $check = $data_akademik->where('nomor_un',$request->nomor_un)->whereNull('deleted_at')->count();
295
296
            if ($check > 0) {
297
                $response['message'] = 'Failed Nomor UN : ' . $request->nomor_un . ' 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...
298
                $response['status']         = true;
299
                $response['error']          = true;
300 View Code Duplication
            } else {
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...
301
                $data_akademik->nomor_un          = $request->input('nomor_un');
302
                $data_akademik->nomor_kk          = $request->input('nomor_kk');
303
                $data_akademik->nama_siswa        = $request->input('nama_siswa');
304
                $data_akademik->tanggal_lahir     = $request->input('tanggal_lahir');
305
                $data_akademik->user_id           = $request->input('user_id');
306
                $data_akademik->bahasa_indonesia  = $request->input('bahasa_indonesia');
307
                $data_akademik->bahasa_inggris    = $request->input('bahasa_inggris');
308
                $data_akademik->matematika        = $request->input('matematika');
309
                $data_akademik->ipa               = $request->input('ipa');
310
                $data_akademik->save();
311
312
                $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...
313
                $response['status']         = true;
314
                $response['error']          = false;
315
            }
316 View Code Duplication
        } else {
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...
317
            $data_akademik->nomor_un          = $request->input('nomor_un');
318
            $data_akademik->nomor_kk          = $request->input('nomor_kk');
319
            $data_akademik->nama_siswa        = $request->input('nama_siswa');
320
            $data_akademik->tanggal_lahir     = $request->input('tanggal_lahir');
321
            $data_akademik->user_id           = $request->input('user_id');
322
            $data_akademik->bahasa_indonesia  = $request->input('bahasa_indonesia');
323
            $data_akademik->bahasa_inggris    = $request->input('bahasa_inggris');
324
            $data_akademik->matematika        = $request->input('matematika');
325
            $data_akademik->ipa               = $request->input('ipa');
326
            $data_akademik->save();
327
328
            $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...
329
            $response['error']          = false;
330
            $response['message']        = 'Success';
331
332
            
333
        }   
334
            
335
336
            return response()->json($response);
337 View Code Duplication
    }else{
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...
338
339
            $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...
340
            $response['message'] = 'Tidak mempunyai akses untuk ini.';
341
342
            return response()->json($response);
343
344
        }
345
346
    }
347
348
    /**
349
     * Remove the specified resource from storage.
350
     *
351
     * @param  \App\DataAkademik  $data_akademik
352
     * @return \Illuminate\Http\Response
0 ignored issues
show
There is no parameter named $data_akademik. 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...
353
     */
354
355
    public function destroy($id)
356
    {
357
        if($this->checkRole(['superadministrator'])){
358
359
        $data_akademik = $this->data_akademik->findOrFail($id);
360
361
        if ($data_akademik->delete()) {
362
            $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...
363
        } else {
364
            $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...
365
        }
366
367
        return json_encode($response);
0 ignored issues
show
Bug Best Practice introduced by
The return type of return json_encode($response); (string) is incompatible with the return type documented by Bantenprov\DataAkademik\...emikController::destroy of type Illuminate\Http\Response.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
368 View Code Duplication
    }else{
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...
369
370
        $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...
371
            $response['message']    = 'Tidak mempunyai akses untuk ini.';
372
373
            return response()->json($response);
374
        }
375
376
    }
377
378
    /* Check Role */
379
380
    protected function checkRole($role = array())
381
    {
382
        return Auth::user()->hasRole($role);
383
    }
384
}
385