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\Nilai\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\Nilai\Facades\NilaiFacade; |
||
10 | |||
11 | /* Models */ |
||
12 | use Bantenprov\Nilai\Models\Bantenprov\Nilai\Nilai; |
||
13 | use Bantenprov\Siswa\Models\Bantenprov\Siswa\Siswa; |
||
14 | use Bantenprov\Kegiatan\Models\Bantenprov\Kegiatan\Kegiatan; |
||
15 | use App\User; |
||
16 | use Bantenprov\Sekolah\Models\Bantenprov\Sekolah\AdminSekolah; |
||
17 | |||
18 | /* Etc */ |
||
19 | use Validator; |
||
20 | use Auth; |
||
21 | |||
22 | /** |
||
23 | * The NilaiController class. |
||
24 | * |
||
25 | * @package Bantenprov\Nilai |
||
26 | * @author bantenprov <[email protected]> |
||
27 | */ |
||
28 | class NilaiController extends Controller |
||
29 | { |
||
30 | protected $siswa; |
||
31 | protected $nilai; |
||
32 | protected $kegiatan; |
||
33 | protected $user; |
||
34 | protected $admin_sekolah; |
||
35 | |||
36 | /** |
||
37 | * Create a new controller instance. |
||
38 | * |
||
39 | * @return void |
||
0 ignored issues
–
show
|
|||
40 | */ |
||
41 | public function __construct(Nilai $nilai, Siswa $siswa, User $user) |
||
42 | { |
||
43 | $this->nilai = new Nilai; |
||
44 | $this->siswa = new Siswa; |
||
45 | $this->kegiatan = new Kegiatan; |
||
46 | $this->user = new User; |
||
47 | $this->admin_sekolah = new AdminSekolah; |
||
48 | } |
||
49 | |||
50 | /** |
||
51 | * Display a listing of the resource. |
||
52 | * |
||
53 | * @return \Illuminate\Http\Response |
||
54 | */ |
||
55 | public function index(Request $request) |
||
56 | { |
||
57 | $admin_sekolah = $this->admin_sekolah->where('admin_sekolah_id', Auth::user()->id)->first(); |
||
58 | |||
59 | if(is_null($admin_sekolah) && $this->checkRole(['superadministrator']) === false){ |
||
60 | $response = []; |
||
61 | return response()->json($response) |
||
62 | ->header('Access-Control-Allow-Origin', '*') |
||
63 | ->header('Access-Control-Allow-Methods', 'GET'); |
||
64 | } |
||
65 | |||
66 | if (request()->has('sort')) { |
||
67 | list($sortCol, $sortDir) = explode('|', request()->sort); |
||
68 | |||
69 | if($this->checkRole(['superadministrator'])){ |
||
70 | $query = $this->nilai->orderBy($sortCol, $sortDir); |
||
0 ignored issues
–
show
The method
orderBy does not exist on object<Bantenprov\Nilai\...Bantenprov\Nilai\Nilai> ? Since you implemented __call , maybe consider adding a @method annotation.
If you implement This is often the case, when class ParentClass {
private $data = array();
public function __call($method, array $args) {
if (0 === strpos($method, 'get')) {
return $this->data[strtolower(substr($method, 3))];
}
throw new \LogicException(sprintf('Unsupported method: %s', $method));
}
}
/**
* If this class knows which fields exist, you can specify the methods here:
*
* @method string getName()
*/
class SomeClass extends ParentClass { }
![]() |
|||
71 | }else{ |
||
72 | $query = $this->nilai->where('user_id', $admin_sekolah->admin_sekolah_id)->orderBy($sortCol, $sortDir); |
||
0 ignored issues
–
show
The method
where does not exist on object<Bantenprov\Nilai\...Bantenprov\Nilai\Nilai> ? Since you implemented __call , maybe consider adding a @method annotation.
If you implement This is often the case, when class ParentClass {
private $data = array();
public function __call($method, array $args) {
if (0 === strpos($method, 'get')) {
return $this->data[strtolower(substr($method, 3))];
}
throw new \LogicException(sprintf('Unsupported method: %s', $method));
}
}
/**
* If this class knows which fields exist, you can specify the methods here:
*
* @method string getName()
*/
class SomeClass extends ParentClass { }
![]() |
|||
73 | } |
||
74 | } else { |
||
75 | if($this->checkRole(['superadministrator'])){ |
||
76 | $query = $this->nilai->orderBy('id', 'asc'); |
||
0 ignored issues
–
show
The method
orderBy does not exist on object<Bantenprov\Nilai\...Bantenprov\Nilai\Nilai> ? Since you implemented __call , maybe consider adding a @method annotation.
If you implement This is often the case, when class ParentClass {
private $data = array();
public function __call($method, array $args) {
if (0 === strpos($method, 'get')) {
return $this->data[strtolower(substr($method, 3))];
}
throw new \LogicException(sprintf('Unsupported method: %s', $method));
}
}
/**
* If this class knows which fields exist, you can specify the methods here:
*
* @method string getName()
*/
class SomeClass extends ParentClass { }
![]() |
|||
77 | }else{ |
||
78 | $query = $this->nilai->where('user_id', $admin_sekolah->admin_sekolah_id)->orderBy('id', 'asc'); |
||
0 ignored issues
–
show
The method
where does not exist on object<Bantenprov\Nilai\...Bantenprov\Nilai\Nilai> ? Since you implemented __call , maybe consider adding a @method annotation.
If you implement This is often the case, when class ParentClass {
private $data = array();
public function __call($method, array $args) {
if (0 === strpos($method, 'get')) {
return $this->data[strtolower(substr($method, 3))];
}
throw new \LogicException(sprintf('Unsupported method: %s', $method));
}
}
/**
* If this class knows which fields exist, you can specify the methods here:
*
* @method string getName()
*/
class SomeClass extends ParentClass { }
![]() |
|||
79 | } |
||
80 | } |
||
81 | |||
82 | if ($request->exists('filter')) { |
||
83 | if($this->checkRole(['superadministrator'])){ |
||
84 | View Code Duplication | $query->where(function($q) use($request) { |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
85 | $value = "%{$request->filter}%"; |
||
86 | |||
87 | $q->where('sekolah_id', 'like', $value) |
||
88 | ->orWhere('admin_sekolah_id', 'like', $value); |
||
89 | }); |
||
90 | }else{ |
||
91 | View Code Duplication | $query->where(function($q) use($request, $admin_sekolah) { |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
92 | $value = "%{$request->filter}%"; |
||
93 | |||
94 | $q->where('sekolah_id', $admin_sekolah->sekolah_id)->where('sekolah_id', 'like', $value); |
||
95 | }); |
||
96 | } |
||
97 | |||
98 | } |
||
99 | |||
100 | $perPage = request()->has('per_page') ? (int) request()->per_page : null; |
||
101 | |||
102 | $response = $query->with(['siswa', 'user', 'nilai_akademik'])->paginate($perPage); |
||
103 | |||
104 | return response()->json($response) |
||
105 | ->header('Access-Control-Allow-Origin', '*') |
||
106 | ->header('Access-Control-Allow-Methods', 'GET'); |
||
107 | } |
||
108 | |||
109 | /** |
||
110 | * Display a listing of the resource. |
||
111 | * |
||
112 | * @return \Illuminate\Http\Response |
||
113 | */ |
||
114 | 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. ![]() |
|||
115 | { |
||
116 | $nilais = $this->nilai->with(['siswa', 'user', 'nilai_akademik'])->get(); |
||
0 ignored issues
–
show
The method
get does only exist in Illuminate\Database\Eloquent\Builder , but not in Illuminate\Database\Eloquent\Model .
It seems like the method you are trying to call exists only in some of the possible types. Let’s take a look at an example: class A
{
public function foo() { }
}
class B extends A
{
public function bar() { }
}
/**
* @param A|B $x
*/
function someFunction($x)
{
$x->foo(); // This call is fine as the method exists in A and B.
$x->bar(); // This method only exists in B and might cause an error.
}
Available Fixes
![]() |
|||
117 | |||
118 | foreach ($nilais as $nilai) { |
||
119 | if ($nilai->siswa !== null) { |
||
120 | array_set($nilai, 'label', $nilai->siswa->nomor_un.' - '.$nilai->siswa->nama_siswa); |
||
121 | } else { |
||
122 | array_set($nilai, 'label', $nilai->nomor_un.' - '); |
||
123 | } |
||
124 | } |
||
125 | |||
126 | $response['nilais'] = $nilais; |
||
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['error'] = false; |
||
128 | $response['message'] = 'Success'; |
||
129 | $response['status'] = true; |
||
130 | |||
131 | return response()->json($response); |
||
132 | } |
||
133 | |||
134 | /** |
||
135 | * Show the form for creating a new resource. |
||
136 | * |
||
137 | * @return \Illuminate\Http\Response |
||
138 | */ |
||
139 | public function create() |
||
140 | { |
||
141 | $user_id = isset(Auth::User()->id) ? Auth::User()->id : null; |
||
142 | $nilai = $this->nilai->getAttributes(); |
||
143 | // $siswas = $this->siswa->getAttributes(); |
||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
54% 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. ![]() |
|||
144 | $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 ![]() |
|||
145 | $users_special = $this->user->all(); |
||
146 | $users_standar = $this->user->findOrFail($user_id); |
||
147 | $current_user = Auth::User(); |
||
148 | |||
149 | $admin_sekolah = $this->admin_sekolah->where('admin_sekolah_id', Auth::user()->id)->first(); |
||
150 | |||
151 | if($this->checkRole(['superadministrator'])){ |
||
152 | $siswas = $this->siswa->all(); |
||
153 | }else{ |
||
154 | $sekolah_id = $admin_sekolah->sekolah_id; |
||
155 | $siswas = $this->siswa->where('sekolah_id', $sekolah_id)->get(); |
||
156 | } |
||
157 | |||
158 | foreach ($siswas as $siswa) { |
||
159 | array_set($siswa, 'label', $siswa->nomor_un.' - '.$siswa->nama_siswa); |
||
160 | } |
||
161 | |||
162 | $role_check = Auth::User()->hasRole(['superadministrator','administrator']); |
||
163 | |||
164 | if ($role_check) { |
||
165 | $user_special = true; |
||
166 | |||
167 | foreach($users_special as $user){ |
||
168 | array_set($user, 'label', $user->name); |
||
169 | } |
||
170 | |||
171 | $users = $users_special; |
||
172 | } else { |
||
173 | $user_special = false; |
||
174 | |||
175 | array_set($users_standar, 'label', $users_standar->name); |
||
176 | |||
177 | $users = $users_standar; |
||
178 | } |
||
179 | |||
180 | array_set($current_user, 'label', $current_user->name); |
||
181 | |||
182 | $response['nilai'] = $nilai; |
||
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. ![]() |
|||
183 | $response['siswa'] = $siswas; |
||
184 | $response['users'] = $users; |
||
185 | $response['user_special'] = $user_special; |
||
186 | $response['current_user'] = $current_user; |
||
187 | $response['error'] = false; |
||
188 | $response['message'] = 'Success'; |
||
189 | $response['status'] = true; |
||
190 | |||
191 | return response()->json($response); |
||
192 | } |
||
193 | |||
194 | /** |
||
195 | * Store a newly created resource in storage. |
||
196 | * |
||
197 | * @param \Illuminate\Http\Request $request |
||
198 | * @return \Illuminate\Http\Response |
||
199 | */ |
||
200 | public function store(Request $request) |
||
201 | { |
||
202 | $nilai = $this->nilai; |
||
203 | |||
204 | $validator = Validator::make($request->all(), [ |
||
205 | 'nomor_un' => "required|exists:{$this->siswa->getTable()},nomor_un|unique:{$this->nilai->getTable()},nomor_un,NULL,id,deleted_at,NULL", |
||
206 | 'bobot' => 'required|numeric|min:0|max:100', |
||
207 | 'akademik' => 'required|numeric|min:0|max:100', |
||
208 | 'prestasi' => 'required|numeric|min:0|max:100', |
||
209 | 'zona' => 'required|numeric|min:0|max:100', |
||
210 | 'sktm' => 'required|numeric|min:0|max:100', |
||
211 | // 'kegiatan_id' => "required|exists:{$this->kegiatan->getTable()},id", |
||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
58% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. ![]() |
|||
212 | // 'total' => 'required|numeric|min:0|max:100', |
||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
58% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. ![]() |
|||
213 | 'user_id' => "required|exists:{$this->user->getTable()},id", |
||
214 | ]); |
||
215 | |||
216 | View Code Duplication | if ($validator->fails()) { |
|
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 | $error = true; |
||
218 | $message = $validator->errors()->first(); |
||
219 | } else { |
||
220 | $nilai->nomor_un = $request->input('nomor_un'); |
||
0 ignored issues
–
show
The property
nomor_un does not exist on object<Bantenprov\Nilai\...Bantenprov\Nilai\Nilai> . Since you implemented __set , maybe consider adding a @property annotation.
Since your code implements the magic setter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
Since the property has write access only, you can use the @property-write annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property. ![]() |
|||
221 | $nilai->bobot = $request->input('bobot'); |
||
0 ignored issues
–
show
The property
bobot does not exist on object<Bantenprov\Nilai\...Bantenprov\Nilai\Nilai> . Since you implemented __set , maybe consider adding a @property annotation.
Since your code implements the magic setter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
Since the property has write access only, you can use the @property-write annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property. ![]() |
|||
222 | $nilai->akademik = $request->input('akademik'); |
||
0 ignored issues
–
show
The property
akademik does not exist on object<Bantenprov\Nilai\...Bantenprov\Nilai\Nilai> . Since you implemented __set , maybe consider adding a @property annotation.
Since your code implements the magic setter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
Since the property has write access only, you can use the @property-write annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property. ![]() |
|||
223 | $nilai->prestasi = $request->input('prestasi'); |
||
0 ignored issues
–
show
The property
prestasi does not exist on object<Bantenprov\Nilai\...Bantenprov\Nilai\Nilai> . Since you implemented __set , maybe consider adding a @property annotation.
Since your code implements the magic setter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
Since the property has write access only, you can use the @property-write annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property. ![]() |
|||
224 | $nilai->zona = $request->input('zona'); |
||
0 ignored issues
–
show
The property
zona does not exist on object<Bantenprov\Nilai\...Bantenprov\Nilai\Nilai> . Since you implemented __set , maybe consider adding a @property annotation.
Since your code implements the magic setter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
Since the property has write access only, you can use the @property-write annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property. ![]() |
|||
225 | $nilai->sktm = $request->input('sktm'); |
||
0 ignored issues
–
show
The property
sktm does not exist on object<Bantenprov\Nilai\...Bantenprov\Nilai\Nilai> . Since you implemented __set , maybe consider adding a @property annotation.
Since your code implements the magic setter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
Since the property has write access only, you can use the @property-write annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property. ![]() |
|||
226 | $nilai->kegiatan_id = null; // $request->input('kegiatan_id'); |
||
0 ignored issues
–
show
The property
kegiatan_id does not exist on object<Bantenprov\Nilai\...Bantenprov\Nilai\Nilai> . Since you implemented __set , maybe consider adding a @property annotation.
Since your code implements the magic setter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
Since the property has write access only, you can use the @property-write annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property. ![]() Unused Code
Comprehensibility
introduced
by
75% 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. ![]() |
|||
227 | $nilai->total = null; // $request->input('total'); |
||
0 ignored issues
–
show
The property
total does not exist on object<Bantenprov\Nilai\...Bantenprov\Nilai\Nilai> . Since you implemented __set , maybe consider adding a @property annotation.
Since your code implements the magic setter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
Since the property has write access only, you can use the @property-write annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property. ![]() Unused Code
Comprehensibility
introduced
by
75% 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. ![]() |
|||
228 | $nilai->user_id = $request->input('user_id'); |
||
0 ignored issues
–
show
The property
user_id does not exist on object<Bantenprov\Nilai\...Bantenprov\Nilai\Nilai> . Since you implemented __set , maybe consider adding a @property annotation.
Since your code implements the magic setter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
Since the property has write access only, you can use the @property-write annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property. ![]() |
|||
229 | $nilai->save(); |
||
230 | |||
231 | $error = false; |
||
232 | $message = 'Success'; |
||
233 | } |
||
234 | |||
235 | $response['nilai'] = $nilai; |
||
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. ![]() |
|||
236 | $response['error'] = $error; |
||
237 | $response['message'] = $message; |
||
238 | $response['status'] = true; |
||
239 | |||
240 | return response()->json($response); |
||
241 | } |
||
242 | |||
243 | /** |
||
244 | * Display the specified resource. |
||
245 | * |
||
246 | * @param \App\Nilai $nilai |
||
0 ignored issues
–
show
There is no parameter named
$nilai . 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. ![]() |
|||
247 | * @return \Illuminate\Http\Response |
||
248 | */ |
||
249 | 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. ![]() |
|||
250 | { |
||
251 | $nilai = $this->nilai->with(['siswa', 'user', 'nilai_akademik'])->findOrFail($id); |
||
0 ignored issues
–
show
The method
findOrFail does only exist in Illuminate\Database\Eloquent\Builder , but not in Illuminate\Database\Eloquent\Model .
It seems like the method you are trying to call exists only in some of the possible types. Let’s take a look at an example: class A
{
public function foo() { }
}
class B extends A
{
public function bar() { }
}
/**
* @param A|B $x
*/
function someFunction($x)
{
$x->foo(); // This call is fine as the method exists in A and B.
$x->bar(); // This method only exists in B and might cause an error.
}
Available Fixes
![]() |
|||
252 | |||
253 | $response['nilai'] = $nilai; |
||
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. ![]() |
|||
254 | $response['error'] = false; |
||
255 | $response['message'] = 'Success'; |
||
256 | $response['status'] = true; |
||
257 | |||
258 | return response()->json($response); |
||
259 | } |
||
260 | |||
261 | /** |
||
262 | * Show the form for editing the specified resource. |
||
263 | * |
||
264 | * @param \App\Nilai $nilai |
||
0 ignored issues
–
show
There is no parameter named
$nilai . 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. ![]() |
|||
265 | * @return \Illuminate\Http\Response |
||
266 | */ |
||
267 | 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. ![]() |
|||
268 | { |
||
269 | $user_id = isset(Auth::User()->id) ? Auth::User()->id : null; |
||
270 | $nilai = $this->nilai->with(['siswa', 'user'])->findOrFail($id); |
||
0 ignored issues
–
show
The method
findOrFail does only exist in Illuminate\Database\Eloquent\Builder , but not in Illuminate\Database\Eloquent\Model .
It seems like the method you are trying to call exists only in some of the possible types. Let’s take a look at an example: class A
{
public function foo() { }
}
class B extends A
{
public function bar() { }
}
/**
* @param A|B $x
*/
function someFunction($x)
{
$x->foo(); // This call is fine as the method exists in A and B.
$x->bar(); // This method only exists in B and might cause an error.
}
Available Fixes
![]() |
|||
271 | $siswas = $this->siswa->getAttributes(); |
||
272 | $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 ![]() |
|||
273 | $users_special = $this->user->all(); |
||
274 | $users_standar = $this->user->findOrFail($user_id); |
||
275 | $current_user = Auth::User(); |
||
276 | |||
277 | if ($nilai->siswa !== null) { |
||
278 | array_set($nilai->siswa, 'label', $nilai->siswa->nomor_un.' - '.$nilai->siswa->nama_siswa); |
||
279 | } |
||
280 | |||
281 | $role_check = Auth::User()->hasRole(['superadministrator','administrator']); |
||
282 | |||
283 | if ($nilai->user !== null) { |
||
284 | array_set($nilai->user, 'label', $nilai->user->name); |
||
285 | } |
||
286 | |||
287 | if ($role_check) { |
||
288 | $user_special = true; |
||
289 | |||
290 | foreach($users_special as $user){ |
||
291 | array_set($user, 'label', $user->name); |
||
292 | } |
||
293 | |||
294 | $users = $users_special; |
||
295 | } else { |
||
296 | $user_special = false; |
||
297 | |||
298 | array_set($users_standar, 'label', $users_standar->name); |
||
299 | |||
300 | $users = $users_standar; |
||
301 | } |
||
302 | |||
303 | array_set($current_user, 'label', $current_user->name); |
||
304 | |||
305 | $response['nilai'] = $nilai; |
||
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. ![]() |
|||
306 | $response['siswas'] = $siswas; |
||
307 | $response['users'] = $users; |
||
308 | $response['user_special'] = $user_special; |
||
309 | $response['current_user'] = $current_user; |
||
310 | $response['error'] = false; |
||
311 | $response['message'] = 'Success'; |
||
312 | $response['status'] = true; |
||
313 | |||
314 | return response()->json($response); |
||
315 | } |
||
316 | |||
317 | /** |
||
318 | * Update the specified resource in storage. |
||
319 | * |
||
320 | * @param \Illuminate\Http\Request $request |
||
321 | * @param \App\Nilai $nilai |
||
0 ignored issues
–
show
There is no parameter named
$nilai . 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. ![]() |
|||
322 | * @return \Illuminate\Http\Response |
||
323 | */ |
||
324 | public function update(Request $request, $id) |
||
325 | { |
||
326 | $nilai = $this->nilai->with(['siswa', 'user'])->findOrFail($id); |
||
0 ignored issues
–
show
The method
findOrFail does only exist in Illuminate\Database\Eloquent\Builder , but not in Illuminate\Database\Eloquent\Model .
It seems like the method you are trying to call exists only in some of the possible types. Let’s take a look at an example: class A
{
public function foo() { }
}
class B extends A
{
public function bar() { }
}
/**
* @param A|B $x
*/
function someFunction($x)
{
$x->foo(); // This call is fine as the method exists in A and B.
$x->bar(); // This method only exists in B and might cause an error.
}
Available Fixes
![]() |
|||
327 | |||
328 | $validator = Validator::make($request->all(), [ |
||
329 | // 'nomor_un' => "required|exists:{$this->siswa->getTable()},nomor_un|unique:{$this->nilai->getTable()},nomor_un,{$id},id,deleted_at,NULL", |
||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
58% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. ![]() |
|||
330 | 'bobot' => 'required|numeric|min:0|max:100', |
||
331 | 'akademik' => 'required|numeric|min:0|max:100', |
||
332 | 'prestasi' => 'required|numeric|min:0|max:100', |
||
333 | 'zona' => 'required|numeric|min:0|max:100', |
||
334 | 'sktm' => 'required|numeric|min:0|max:100', |
||
335 | // 'kegiatan_id' => "required|exists:{$this->kegiatan->getTable()},id", |
||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
58% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. ![]() |
|||
336 | // 'total' => 'required|numeric|min:0|max:100', |
||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
58% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. ![]() |
|||
337 | 'user_id' => "required|exists:{$this->user->getTable()},id", |
||
338 | ]); |
||
339 | |||
340 | View Code Duplication | if ($validator->fails()) { |
|
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. ![]() |
|||
341 | $error = true; |
||
342 | $message = $validator->errors()->first(); |
||
343 | } else { |
||
344 | $nilai->nomor_un = $nilai->nomor_un; // $request->input('nomor_un'); |
||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
75% 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. ![]() |
|||
345 | $nilai->bobot = $request->input('bobot'); |
||
346 | $nilai->akademik = $request->input('akademik'); |
||
347 | $nilai->prestasi = $request->input('prestasi'); |
||
348 | $nilai->zona = $request->input('zona'); |
||
349 | $nilai->sktm = $request->input('sktm'); |
||
350 | $nilai->kegiatan_id = null; // $request->input('kegiatan_id'); |
||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
75% 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. ![]() |
|||
351 | $nilai->total = null; // $request->input('total'); |
||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
75% 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. ![]() |
|||
352 | $nilai->user_id = $request->input('user_id'); |
||
353 | $nilai->save(); |
||
354 | |||
355 | $error = false; |
||
356 | $message = 'Success'; |
||
357 | } |
||
358 | |||
359 | $response['nilai'] = $nilai; |
||
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. ![]() |
|||
360 | $response['error'] = $error; |
||
361 | $response['message'] = $message; |
||
362 | $response['status'] = true; |
||
363 | |||
364 | return response()->json($response); |
||
365 | } |
||
366 | |||
367 | /** |
||
368 | * Remove the specified resource from storage. |
||
369 | * |
||
370 | * @param \App\Nilai $nilai |
||
0 ignored issues
–
show
There is no parameter named
$nilai . 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. ![]() |
|||
371 | * @return \Illuminate\Http\Response |
||
372 | */ |
||
373 | 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. ![]() |
|||
374 | { |
||
375 | $nilai = $this->nilai->findOrFail($id); |
||
0 ignored issues
–
show
The method
findOrFail does not exist on object<Bantenprov\Nilai\...Bantenprov\Nilai\Nilai> ? Since you implemented __call , maybe consider adding a @method annotation.
If you implement This is often the case, when class ParentClass {
private $data = array();
public function __call($method, array $args) {
if (0 === strpos($method, 'get')) {
return $this->data[strtolower(substr($method, 3))];
}
throw new \LogicException(sprintf('Unsupported method: %s', $method));
}
}
/**
* If this class knows which fields exist, you can specify the methods here:
*
* @method string getName()
*/
class SomeClass extends ParentClass { }
![]() |
|||
376 | |||
377 | if ($nilai->delete()) { |
||
378 | $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. ![]() |
|||
379 | $response['success'] = true; |
||
380 | $response['status'] = true; |
||
381 | } else { |
||
382 | $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. ![]() |
|||
383 | $response['success'] = false; |
||
384 | $response['status'] = false; |
||
385 | } |
||
386 | |||
387 | return json_encode($response); |
||
388 | } |
||
389 | |||
390 | protected function checkRole($role = array()) |
||
391 | { |
||
392 | return Auth::user()->hasRole($role); |
||
393 | } |
||
394 | } |
||
395 |
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.