This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
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\Zona\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\Zona\Facades\ZonaFacade; |
||
10 | |||
11 | /* Models */ |
||
12 | use Bantenprov\Zona\Models\Bantenprov\Zona\MasterZona; |
||
13 | use App\User; |
||
14 | |||
15 | /* Etc */ |
||
16 | use Validator; |
||
17 | use Auth; |
||
18 | |||
19 | /** |
||
20 | * The MasterZonaController class. |
||
21 | * |
||
22 | * @package Bantenprov\Zona |
||
23 | * @author bantenprov <[email protected]> |
||
24 | */ |
||
25 | class MasterZonaController extends Controller |
||
26 | { |
||
27 | protected $master_zona; |
||
28 | protected $user; |
||
29 | |||
30 | /** |
||
31 | * Create a new controller instance. |
||
32 | * |
||
33 | * @return void |
||
0 ignored issues
–
show
|
|||
34 | */ |
||
35 | public function __construct() |
||
36 | { |
||
37 | $this->master_zona = new MasterZona; |
||
38 | $this->user = new User; |
||
39 | } |
||
40 | |||
41 | /** |
||
42 | * Display a listing of the resource. |
||
43 | * |
||
44 | * @return \Illuminate\Http\Response |
||
45 | */ |
||
46 | public function index(Request $request) |
||
47 | { |
||
48 | if (request()->has('sort')) { |
||
49 | list($sortCol, $sortDir) = explode('|', request()->sort); |
||
50 | |||
51 | $query = $this->master_zona->orderBy($sortCol, $sortDir); |
||
52 | } else { |
||
53 | $query = $this->master_zona->orderBy('id', 'asc'); |
||
54 | } |
||
55 | |||
56 | if ($request->exists('filter')) { |
||
57 | $query->where(function($q) use($request) { |
||
58 | $value = "%{$request->filter}%"; |
||
59 | |||
60 | $q->where('tingkat', 'like', $value) |
||
61 | ->orWhere('kode', 'like', $value) |
||
62 | ->orWhere('label', 'like', $value); |
||
63 | }); |
||
64 | } |
||
65 | |||
66 | $perPage = request()->has('per_page') ? (int) request()->per_page : null; |
||
67 | |||
68 | $response = $query->with(['user'])->paginate($perPage); |
||
69 | |||
70 | return response()->json($response) |
||
71 | ->header('Access-Control-Allow-Origin', '*') |
||
72 | ->header('Access-Control-Allow-Methods', 'GET'); |
||
73 | } |
||
74 | |||
75 | /** |
||
76 | * Display a listing of the resource. |
||
77 | * |
||
78 | * @return \Illuminate\Http\Response |
||
79 | */ |
||
80 | View Code Duplication | public function get() |
|
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. ![]() |
|||
81 | { |
||
82 | $master_zonas = $this->master_zona->with(['user'])->get(); |
||
83 | |||
84 | $response['master_zonas'] = $master_zonas; |
||
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 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. ![]() |
|||
85 | $response['error'] = false; |
||
86 | $response['message'] = 'Success'; |
||
87 | $response['status'] = true; |
||
88 | |||
89 | return response()->json($response); |
||
90 | } |
||
91 | |||
92 | /** |
||
93 | * Show the form for creating a new resource. |
||
94 | * |
||
95 | * @return \Illuminate\Http\Response |
||
96 | */ |
||
97 | public function create() |
||
98 | { |
||
99 | $user_id = isset(Auth::User()->id) ? Auth::User()->id : null; |
||
100 | $master_zona = $this->master_zona->getAttributes(); |
||
101 | $users = $this->user->getAttributes(); |
||
0 ignored issues
–
show
$users is not used, you could remove the assignment.
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently. $myVar = 'Value';
$higher = false;
if (rand(1, 6) > 3) {
$higher = true;
} else {
$higher = false;
}
Both the ![]() |
|||
102 | $users_special = $this->user->all(); |
||
103 | $users_standar = $this->user->findOrFail($user_id); |
||
104 | $current_user = Auth::User(); |
||
105 | |||
106 | $role_check = Auth::User()->hasRole(['superadministrator','administrator']); |
||
107 | |||
108 | 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. ![]() |
|||
109 | $user_special = true; |
||
110 | |||
111 | foreach ($users_special as $user) { |
||
112 | array_set($user, 'label', $user->name); |
||
113 | } |
||
114 | |||
115 | $users = $users_special; |
||
116 | } else { |
||
117 | $user_special = false; |
||
118 | |||
119 | array_set($users_standar, 'label', $users_standar->name); |
||
120 | |||
121 | $users = $users_standar; |
||
122 | } |
||
123 | |||
124 | array_set($current_user, 'label', $current_user->name); |
||
125 | |||
126 | $response['master_zona'] = $master_zona; |
||
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 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. ![]() |
|||
127 | $response['users'] = $users; |
||
128 | $response['user_special'] = $user_special; |
||
129 | $response['current_user'] = $current_user; |
||
130 | $response['error'] = false; |
||
131 | $response['message'] = 'Success'; |
||
132 | $response['status'] = true; |
||
133 | |||
134 | return response()->json($response); |
||
135 | } |
||
136 | |||
137 | /** |
||
138 | * Store a newly created resource in storage. |
||
139 | * |
||
140 | * @param \Illuminate\Http\Request $request |
||
141 | * @return \Illuminate\Http\Response |
||
142 | */ |
||
143 | View Code Duplication | public function store(Request $request) |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
144 | { |
||
145 | $master_zona = $this->master_zona; |
||
146 | |||
147 | $validator = Validator::make($request->all(), [ |
||
148 | 'tingkat' => 'required|numeric', |
||
149 | 'kode' => "required|numeric|unique:{$this->master_zona->getTable()},kode,NULL,id,deleted_at,NULL", |
||
150 | 'label' => 'required|max:255', |
||
151 | 'user_id' => "required|exists:{$this->user->getTable()},id", |
||
152 | ]); |
||
153 | |||
154 | if ($validator->fails()) { |
||
155 | $error = true; |
||
156 | $message = $validator->errors()->first(); |
||
157 | } else { |
||
158 | $master_zona->id = $request->input('kode'); |
||
159 | $master_zona->tingkat = $request->input('tingkat'); |
||
160 | $master_zona->kode = $request->input('kode'); |
||
161 | $master_zona->label = $request->input('label'); |
||
162 | $master_zona->user_id = $request->input('user_id'); |
||
163 | $master_zona->save(); |
||
164 | |||
165 | $error = false; |
||
166 | $message = 'Success'; |
||
167 | } |
||
168 | |||
169 | $response['master_zona'] = $master_zona; |
||
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 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. ![]() |
|||
170 | $response['error'] = $error; |
||
171 | $response['message'] = $message; |
||
172 | $response['status'] = true; |
||
173 | |||
174 | return response()->json($response); |
||
175 | } |
||
176 | |||
177 | /** |
||
178 | * Display the specified resource. |
||
179 | * |
||
180 | * @param \App\MasterZona $master-zona |
||
0 ignored issues
–
show
There is no parameter named
$master-zona . 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 /**
* @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. ![]() |
|||
181 | * @return \Illuminate\Http\Response |
||
182 | */ |
||
183 | 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. ![]() |
|||
184 | { |
||
185 | $master_zona = $this->master_zona->with(['user'])->findOrFail($id); |
||
186 | |||
187 | $response['master_zona'] = $master_zona; |
||
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 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. ![]() |
|||
188 | $response['error'] = false; |
||
189 | $response['message'] = 'Success'; |
||
190 | $response['status'] = true; |
||
191 | |||
192 | return response()->json($response); |
||
193 | } |
||
194 | |||
195 | /** |
||
196 | * Show the form for editing the specified resource. |
||
197 | * |
||
198 | * @param \App\MasterZona $master_zona |
||
0 ignored issues
–
show
There is no parameter named
$master_zona . 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 /**
* @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. ![]() |
|||
199 | * @return \Illuminate\Http\Response |
||
200 | */ |
||
201 | public function edit($id) |
||
202 | { |
||
203 | $user_id = isset(Auth::User()->id) ? Auth::User()->id : null; |
||
204 | $master_zona = $this->master_zona->with(['user'])->findOrFail($id); |
||
205 | $users = $this->user->getAttributes(); |
||
0 ignored issues
–
show
$users is not used, you could remove the assignment.
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently. $myVar = 'Value';
$higher = false;
if (rand(1, 6) > 3) {
$higher = true;
} else {
$higher = false;
}
Both the ![]() |
|||
206 | $users_special = $this->user->all(); |
||
207 | $users_standar = $this->user->findOrFail($user_id); |
||
208 | $current_user = Auth::User(); |
||
209 | |||
210 | $role_check = Auth::User()->hasRole(['superadministrator','administrator']); |
||
211 | |||
212 | if ($master_zona->user !== null) { |
||
213 | array_set($master_zona->user, 'label', $master_zona->user->name); |
||
214 | } |
||
215 | |||
216 | 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. ![]() |
|||
217 | $user_special = true; |
||
218 | |||
219 | foreach ($users_special as $user) { |
||
220 | array_set($user, 'label', $user->name); |
||
221 | } |
||
222 | |||
223 | $users = $users_special; |
||
224 | } else { |
||
225 | $user_special = false; |
||
226 | |||
227 | array_set($users_standar, 'label', $users_standar->name); |
||
228 | |||
229 | $users = $users_standar; |
||
230 | } |
||
231 | |||
232 | array_set($current_user, 'label', $current_user->name); |
||
233 | |||
234 | $response['master_zona'] = $master_zona; |
||
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 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. ![]() |
|||
235 | $response['users'] = $users; |
||
236 | $response['user_special'] = $user_special; |
||
237 | $response['current_user'] = $current_user; |
||
238 | $response['error'] = false; |
||
239 | $response['message'] = 'Success'; |
||
240 | $response['status'] = true; |
||
241 | |||
242 | return response()->json($response); |
||
243 | } |
||
244 | |||
245 | /** |
||
246 | * Update the specified resource in storage. |
||
247 | * |
||
248 | * @param \Illuminate\Http\Request $request |
||
249 | * @param \App\MasterZona $master_zona |
||
0 ignored issues
–
show
There is no parameter named
$master_zona . 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 /**
* @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. ![]() |
|||
250 | * @return \Illuminate\Http\Response |
||
251 | */ |
||
252 | View Code Duplication | public function update(Request $request, $id) |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
253 | { |
||
254 | $master_zona = $this->master_zona->with(['user'])->findOrFail($id); |
||
255 | |||
256 | $validator = Validator::make($request->all(), [ |
||
257 | 'tingkat' => 'required|numeric', |
||
258 | 'kode' => "required|numeric|unique:{$this->master_zona->getTable()},kode,{$id},id,deleted_at,NULL", |
||
259 | 'label' => 'required|max:255', |
||
260 | 'user_id' => "required|exists:{$this->user->getTable()},id", |
||
261 | ]); |
||
262 | |||
263 | if ($validator->fails()) { |
||
264 | $error = true; |
||
265 | $message = $validator->errors()->first(); |
||
266 | } else { |
||
267 | $master_zona->id = $request->input('kode'); |
||
268 | $master_zona->tingkat = $request->input('tingkat'); |
||
269 | $master_zona->kode = $request->input('kode'); |
||
270 | $master_zona->label = $request->input('label'); |
||
271 | $master_zona->user_id = $request->input('user_id'); |
||
272 | $master_zona->save(); |
||
273 | |||
274 | $error = false; |
||
275 | $message = 'Success'; |
||
276 | } |
||
277 | |||
278 | $response['error'] = $error; |
||
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 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. ![]() |
|||
279 | $response['message'] = $message; |
||
280 | $response['status'] = true; |
||
281 | |||
282 | return response()->json($response); |
||
283 | } |
||
284 | |||
285 | /** |
||
286 | * Remove the specified resource from storage. |
||
287 | * |
||
288 | * @param \App\MasterZona $master_zona |
||
0 ignored issues
–
show
There is no parameter named
$master_zona . 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 /**
* @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. ![]() |
|||
289 | * @return \Illuminate\Http\Response |
||
290 | */ |
||
291 | 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. ![]() |
|||
292 | { |
||
293 | $master_zona = $this->master_zona->findOrFail($id); |
||
294 | |||
295 | if ($master_zona->delete()) { |
||
296 | $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 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. ![]() |
|||
297 | $response['success'] = true; |
||
298 | $response['status'] = true; |
||
299 | } else { |
||
300 | $response['message'] = 'Failed'; |
||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
$response was never initialized. Although not strictly required by PHP, it is generally a good practice to add $response = array(); before regardless.
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code. Let’s take a look at an example: foreach ($collection as $item) {
$myArray['foo'] = $item->getFoo();
if ($item->hasBar()) {
$myArray['bar'] = $item->getBar();
}
// do something with $myArray
}
As you can see in this example, the array 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. ![]() |
|||
301 | $response['success'] = false; |
||
302 | $response['status'] = false; |
||
303 | } |
||
304 | |||
305 | return json_encode($response); |
||
306 | } |
||
307 | } |
||
308 |
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.