Issues (27)

Security Analysis    not enabled

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/VueOpdController.php (21 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\VueOpd\Http\Controllers;
4
5
/* Require */
6
use App\Http\Controllers\Controller;
7
use Illuminate\Http\Request;
8
use Illuminate\Validation\Rule;
9
use Bantenprov\VueOpd\Facades\VueOpdFacade;
10
11
/* Models */
12
use Bantenprov\VueOpd\Models\Bantenprov\VueOpd\VueOpd;
13
14
/* Etc */
15
use Validator;
16
17
/**
18
 * The VueOpdController class.
19
 *
20
 * @package Bantenprov\VueOpd
21
 * @author  bantenprov <[email protected]>
22
 */
23
class VueOpdController extends Controller
24
{
25
    /**
26
     * Create a new controller instance.
27
     *
28
     * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
29
     */
30
    public function __construct(VueOpd $vue_opd)
31
    {
32
        $this->vue_opd = $vue_opd;
33
    }
34
35
    /**
36
     * Display a listing of the resource.
37
     *
38
     * @return \Illuminate\Http\Response
39
     */
40
    public function index(Request $request)
41
    {
42
        if (request()->has('sort')) {
43
            list($sortCol, $sortDir) = explode('|', request()->sort);
44
45
            $query = $this->vue_opd->orderBy($sortCol, $sortDir);
46
        } else {
47
            $query = $this->vue_opd->orderBy('id', 'asc');
48
        }
49
50
        if ($request->exists('filter')) {
51
            $query->where(function($q) use($request) {
52
                $value = "%{$request->filter}%";
53
                $q->where('id', 'like', $value)
54
                    ->orWhere('kunker', 'like', $value)
55
                    ->orWhere('name', 'like', $value)
56
                    ->orWhere('kunker_sinjab', 'like', $value)
57
                    ->orWhere('kunker_simral', 'like', $value)
58
                    ->orWhere('levelunker', 'like', $value)
59
                    ->orWhere('njab', 'like', $value)
60
                    ->orWhere('npej', 'like', $value);
61
            });
62
        }
63
64
        $perPage = request()->has('per_page') ? (int) request()->per_page : null;
65
        $response = $query->paginate($perPage);
66
67
        return response()->json($response)
68
            ->header('Access-Control-Allow-Origin', '*')
69
            ->header('Access-Control-Allow-Methods', 'GET');
70
    }
71
72
    /**
73
     * Show the form for creating a new resource.
74
     *
75
     * @return \Illuminate\Http\Response
76
     */
77
    public function create($id = null)
78
    {
79
        $vue_opd = $this->vue_opd;
80
81
        if ($id == null) {
82
            $vue_opd->id            = null;
83
            $vue_opd->kunker        = null;
84
            $vue_opd->name          = null;
85
            $vue_opd->kunker_sinjab = null;
86
            $vue_opd->kunker_simral = null;
87
            $vue_opd->levelunker    = 1;
88
            $vue_opd->njab          = null;
89
            $vue_opd->npej          = null;
90
91
            $response['vue_opd'] = $vue_opd;
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...
92
            $response['loaded'] = true;
93
        } else {
94
            $vue_opd->id            = null;
95
            $vue_opd->kunker        = null;
96
            $vue_opd->name          = null;
97
            $vue_opd->kunker_sinjab = null;
98
            $vue_opd->kunker_simral = null;
99
            $vue_opd->levelunker    = $this->vue_opd->findOrFail($id)->levelunker + 1;
100
            $vue_opd->njab          = null;
101
            $vue_opd->npej          = null;
102
103
            $response['vue_opd'] = $vue_opd;
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...
104
            $response['loaded'] = 1 == $vue_opd->levelunker < 5 ? true : false;
105
        }
106
107
        return response()->json($response);
108
    }
109
110
    /**
111
     * Display the specified resource.
112
     *
113
     * @param  \App\VueOpd  $vue_opd
0 ignored issues
show
There is no parameter named $vue_opd. 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...
114
     * @return \Illuminate\Http\Response
115
     */
116
    public function store(Request $request, $id = null)
117
    {
118
        $vue_opd = $this->vue_opd;
119
120
        if ($id == null) {
121
            $validator = Validator::make($request->all(), [
122
                'kunker'            => 'required|numeric|digits:15|unique:vue_opds,kunker,NULL,id,deleted_at,NULL',
123
                'name'              => 'required|max:255',
124
                'kunker_sinjab'     => 'nullable|numeric|max:255',
125
                'kunker_simral'     => 'nullable|numeric|max:255',
126
                'levelunker'        => [
127
                                        'required',
128
                                        Rule::in([1]),
129
                ],
130
                'njab'              => 'required|max:255',
131
                'npej'              => 'required|max:255',
132
            ]);
133
        } else {
134
            $validator = Validator::make($request->all(), [
135
                'kunker'            => 'required|numeric|digits:15|unique:vue_opds,kunker,NULL,id,deleted_at,NULL',
136
                'name'              => 'required|max:255',
137
                'kunker_sinjab'     => 'nullable|numeric|max:255',
138
                'kunker_simral'     => 'nullable|numeric|max:255',
139
                'levelunker'        => [
140
                                        'required',
141
                                        Rule::in([2,3,4,5]),
142
                ],
143
                'njab'              => 'required|max:255',
144
                'npej'              => 'required|max:255',
145
            ]);
146
        }
147
148
        if($validator->fails()){
149
            $response['error'] = true;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$response was never initialized. Although not strictly required by PHP, it is generally a good practice to add $response = array(); before regardless.

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

Let’s take a look at an example:

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

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

    // do something with $myArray
}

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

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

Loading history...
150
            $response['message'] = $validator->errors()->first();
151
        } else {
152
            if ($id == null) {
153
                $vue_opd->kunker        = $request->kunker;
154
                $vue_opd->name          = $request->name;
155
                $vue_opd->kunker_sinjab = $request->kunker_sinjab;
156
                $vue_opd->kunker_simral = $request->kunker_simral;
157
                $vue_opd->levelunker    = 1;
158
                $vue_opd->njab          = $request->njab;
159
                $vue_opd->npej          = $request->npej;
160
                // $vue_opd->parent_id     = null;
0 ignored issues
show
Unused Code Comprehensibility introduced by
45% 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...
161
                $vue_opd->save();
162
            } else {
163
                $vue_opd->kunker        = $request->kunker;
164
                $vue_opd->name          = $request->name;
165
                $vue_opd->kunker_sinjab = $request->kunker_sinjab;
166
                $vue_opd->kunker_simral = $request->kunker_simral;
167
                $vue_opd->levelunker    = $this->vue_opd->findOrFail($id)->levelunker + 1;
168
                $vue_opd->njab          = $request->njab;
169
                $vue_opd->npej          = $request->npej;
170
                $vue_opd->parent_id     = $this->vue_opd->findOrFail($id)->id;
171
                $vue_opd->save();
172
            }
173
174
            $response['error'] = 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...
175
            $response['message'] = 'Success';
176
        }
177
178
        $response['loaded'] = true;
179
180
        return response()->json($response);
181
    }
182
183
    /**
184
     * Store a newly created resource in storage.
185
     *
186
     * @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...
187
     * @return \Illuminate\Http\Response
188
     */
189 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...
190
    {
191
        $vue_opd = $this->vue_opd->findOrFail($id);
192
193
        $response['vue_opd'] = $vue_opd;
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...
194
        $response['loaded'] = true;
195
196
        return response()->json($response);
197
    }
198
199
    /**
200
     * Show the form for editing the specified resource.
201
     *
202
     * @param  \App\VueOpd  $vue_opd
0 ignored issues
show
There is no parameter named $vue_opd. 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...
203
     * @return \Illuminate\Http\Response
204
     */
205 View Code Duplication
    public function edit($id)
0 ignored issues
show
This method seems to be duplicated in your project.

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

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

Loading history...
206
    {
207
        $vue_opd = $this->vue_opd->findOrFail($id);
208
209
        $response['vue_opd'] = $vue_opd;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$response was never initialized. Although not strictly required by PHP, it is generally a good practice to add $response = array(); before regardless.

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

Let’s take a look at an example:

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

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

    // do something with $myArray
}

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

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

Loading history...
210
        $response['loaded'] = true;
211
212
        return response()->json($response);
213
    }
214
215
    /**
216
     * Update the specified resource in storage.
217
     *
218
     * @param  \Illuminate\Http\Request  $request
219
     * @param  \App\VueOpd  $vue_opd
0 ignored issues
show
There is no parameter named $vue_opd. 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...
220
     * @return \Illuminate\Http\Response
221
     */
222
    public function update(Request $request, $id)
223
    {
224
        $vue_opd = $this->vue_opd->findOrFail($id);
225
226
        $validator = Validator::make($request->all(), [
227
            'kunker'            => 'required|numeric|digits:15|unique:vue_opds,kunker,'.$id.',id,deleted_at,NULL',
228
            'name'              => 'required|max:255',
229
            'kunker_sinjab'     => 'nullable|numeric|max:255',
230
            'kunker_simral'     => 'nullable|numeric|max:255',
231
            'levelunker'        => [
232
                                    'required',
233
                                    Rule::in([1,2,3,4,5]),
234
            ],
235
            'njab'              => 'required|max:255',
236
            'npej'              => 'required|max:255',
237
        ]);
238
239
        if($validator->fails()){
240
            $response['error'] = true;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$response was never initialized. Although not strictly required by PHP, it is generally a good practice to add $response = array(); before regardless.

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

Let’s take a look at an example:

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

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

    // do something with $myArray
}

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

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

Loading history...
241
            $response['message'] = $validator->errors()->first();
242
        } else {
243
            $vue_opd->kunker        = $request->kunker;
244
            $vue_opd->name          = $request->name;
245
            $vue_opd->kunker_sinjab = $request->kunker_sinjab;
246
            $vue_opd->kunker_simral = $request->kunker_simral;
247
            // $vue_opd->levelunker    = $request->levelunker;
0 ignored issues
show
Unused Code Comprehensibility introduced by
46% 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...
248
            $vue_opd->njab          = $request->njab;
249
            $vue_opd->npej          = $request->npej;
250
            $vue_opd->save();
251
252
            $response['error'] = 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...
253
            $response['message'] = 'Success';
254
        }
255
256
        $response['loaded'] = true;
257
258
        return response()->json($response);
259
    }
260
261
    /**
262
     * Remove the specified resource from storage.
263
     *
264
     * @param  \App\VueOpd  $vue_opd
0 ignored issues
show
There is no parameter named $vue_opd. 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...
265
     * @return \Illuminate\Http\Response
266
     */
267 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...
268
    {
269
        $vue_opd = $this->vue_opd->findOrFail($id);
270
271
        if ($vue_opd->delete()) {
272
            $response['loaded'] = 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...
273
        } else {
274
            $response['loaded'] = 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...
275
        }
276
277
        return json_encode($response);
278
    }
279
}
280