Issues (125)

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/AkademikController.php (41 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\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\Akademik;
13
use Bantenprov\Siswa\Models\Bantenprov\Siswa\Siswa;
14
use App\User;
15
use Bantenprov\Nilai\Models\Bantenprov\Nilai\Nilai;
16
17
/* Etc */
18
use Validator;
19
use Auth;
20
21
/**
22
 * The AkademikController class.
23
 *
24
 * @package Bantenprov\Nilai
25
 * @author  bantenprov <[email protected]>
26
 */
27
class AkademikController extends Controller
28
{
29
    protected $akademik;
30
    protected $siswa;
31
    protected $user;
32
    protected $nilai;
33
34
    /**
35
     * Create a new controller instance.
36
     *
37
     * @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...
38
     */
39
    public function __construct()
40
    {
41
        $this->akademik = new Akademik;
42
        $this->siswa    = new Siswa;
43
        $this->user     = new User;
44
        $this->nilai    = new Nilai;
45
    }
46
47
    /**
48
     * Display a listing of the resource.
49
     *
50
     * @return \Illuminate\Http\Response
51
     */
52
    public function index(Request $request)
53
    {
54
        if (request()->has('sort')) {
55
            list($sortCol, $sortDir) = explode('|', request()->sort);
56
57
            $query = $this->akademik->orderBy($sortCol, $sortDir);
0 ignored issues
show
Documentation Bug introduced by
The method orderBy does not exist on object<Bantenprov\Nilai\...tenprov\Nilai\Akademik>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

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 { }
Loading history...
58
        } else {
59
            $query = $this->akademik->orderBy('id', 'asc');
0 ignored issues
show
Documentation Bug introduced by
The method orderBy does not exist on object<Bantenprov\Nilai\...tenprov\Nilai\Akademik>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

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 { }
Loading history...
60
        }
61
62
        if ($request->exists('filter')) {
63
            $query->where(function($q) use($request) {
64
                $value = "%{$request->filter}%";
65
66
                $q->where('nomor_un', 'like', $value);
67
            });
68
        }
69
70
        $perPage    = request()->has('per_page') ? (int) request()->per_page : null;
71
72
        $response   = $query->with(['siswa', 'user'])->paginate($perPage);
73
74
        return response()->json($response)
75
            ->header('Access-Control-Allow-Origin', '*')
76
            ->header('Access-Control-Allow-Methods', 'GET');
77
    }
78
79
    /**
80
     * Display a listing of the resource.
81
     *
82
     * @return \Illuminate\Http\Response
83
     */
84 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.

Loading history...
85
    {
86
        $akademiks = $this->akademik->with(['siswa', 'user'])->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

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
87
88
        foreach ($akademiks as $akademik) {
89
            if ($akademik->siswa !== null) {
90
                array_set($akademik, 'label', $akademik->siswa->nomor_un.' - '.$akademik->siswa->nama_siswa);
91
            } else {
92
                array_set($akademik, 'label', $akademik->nomor_un.' - ');
93
            }
94
        }
95
96
        $response['akademiks']  = $akademiks;
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...
97
        $response['error']      = false;
98
        $response['message']    = 'Success';
99
        $response['status']     = true;
100
101
        return response()->json($response);
102
    }
103
104
    /**
105
     * Show the form for creating a new resource.
106
     *
107
     * @return \Illuminate\Http\Response
108
     */
109
    public function create()
110
    {
111
        $user_id        = isset(Auth::User()->id) ? Auth::User()->id : null;
112
        $akademik       = $this->akademik->getAttributes();
113
        $siswas         = $this->siswa->getAttributes();
114
        $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 $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
115
        $users_special  = $this->user->all();
116
        $users_standar  = $this->user->findOrFail($user_id);
117
        $current_user   = Auth::User();
118
119
        foreach ($siswas as $siswa) {
120
            array_set($siswa, 'label', $siswa->nomor_un.' - '.$siswa->nama_siswa);
121
        }
122
123
        $role_check = Auth::User()->hasRole(['superadministrator','administrator']);
124
125
        if ($role_check) {
126
            $user_special = true;
127
128
            foreach($users_special as $user){
129
                array_set($user, 'label', $user->name);
130
            }
131
132
            $users = $users_special;
133
        } else {
134
            $user_special = false;
135
136
            array_set($users_standar, 'label', $users_standar->name);
137
138
            $users = $users_standar;
139
        }
140
141
        array_set($current_user, 'label', $current_user->name);
142
143
        $response['akademik']       = $akademik;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$response was never initialized. Although not strictly required by PHP, it is generally a good practice to add $response = array(); before regardless.

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

Let’s take a look at an example:

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

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

    // do something with $myArray
}

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

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

Loading history...
144
        $response['siswas']         = $siswas;
145
        $response['users']          = $users;
146
        $response['user_special']   = $user_special;
147
        $response['current_user']   = $current_user;
148
        $response['error']          = false;
149
        $response['message']        = 'Success';
150
        $response['status']         = true;
151
152
        return response()->json($response);
153
    }
154
155
    /**
156
     * Store a newly created resource in storage.
157
     *
158
     * @param  \Illuminate\Http\Request  $request
159
     * @return \Illuminate\Http\Response
160
     */
161
    public function store(Request $request)
162
    {
163
        $akademik = $this->akademik;
164
165
        $validator = Validator::make($request->all(), [
166
            'nomor_un'          => "required|exists:{$this->siswa->getTable()},nomor_un|unique:{$this->akademik->getTable()},nomor_un,NULL,id,deleted_at,NULL",
167
            'bahasa_indonesia'  => 'required|numeric|min:0|max:100',
168
            'bahasa_inggris'    => 'required|numeric|min:0|max:100',
169
            'matematika'        => 'required|numeric|min:0|max:100',
170
            'ipa'               => 'required|numeric|min:0|max:100',
171
            'user_id'           => "required|exists:{$this->user->getTable()},id",
172
        ]);
173
174 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.

Loading history...
175
            $error      = true;
176
            $message    = $validator->errors()->first();
177
        } else {
178
            $akademik->nomor_un         = $request->input('nomor_un');
0 ignored issues
show
The property nomor_un does not exist on object<Bantenprov\Nilai\...tenprov\Nilai\Akademik>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?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.

Loading history...
179
            $akademik->bahasa_indonesia = $request->input('bahasa_indonesia');
0 ignored issues
show
The property bahasa_indonesia does not exist on object<Bantenprov\Nilai\...tenprov\Nilai\Akademik>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?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.

Loading history...
180
            $akademik->bahasa_inggris   = $request->input('bahasa_inggris');
0 ignored issues
show
The property bahasa_inggris does not exist on object<Bantenprov\Nilai\...tenprov\Nilai\Akademik>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?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.

Loading history...
181
            $akademik->matematika       = $request->input('matematika');
0 ignored issues
show
The property matematika does not exist on object<Bantenprov\Nilai\...tenprov\Nilai\Akademik>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?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.

Loading history...
182
            $akademik->ipa              = $request->input('ipa');
0 ignored issues
show
The property ipa does not exist on object<Bantenprov\Nilai\...tenprov\Nilai\Akademik>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?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.

Loading history...
183
            $akademik->user_id          = $request->input('user_id');
0 ignored issues
show
The property user_id does not exist on object<Bantenprov\Nilai\...tenprov\Nilai\Akademik>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?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.

Loading history...
184
185
            $nilai = $this->nilai->updateOrCreate(
0 ignored issues
show
Documentation Bug introduced by
The method updateOrCreate does not exist on object<Bantenprov\Nilai\...Bantenprov\Nilai\Nilai>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

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 { }
Loading history...
186
                [
187
                    'nomor_un'  => $akademik->nomor_un,
0 ignored issues
show
The property nomor_un does not exist on object<Bantenprov\Nilai\...tenprov\Nilai\Akademik>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?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.");
        }
    }

}

If the property has read access only, you can use the @property-read 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.

Loading history...
188
                ],
189
                [
190
                    'nomor_un'  => $akademik->nomor_un,
0 ignored issues
show
The property nomor_un does not exist on object<Bantenprov\Nilai\...tenprov\Nilai\Akademik>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?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.");
        }
    }

}

If the property has read access only, you can use the @property-read 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.

Loading history...
191
                    'bobot'     => $akademik->calcNilaiBobot($request),
192
                    'akademik'  => $akademik->calcNilaiAkademik($request),
193
                    'total'     => null,
194
                    'user_id'   => $akademik->user_id,
0 ignored issues
show
The property user_id does not exist on object<Bantenprov\Nilai\...tenprov\Nilai\Akademik>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?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.");
        }
    }

}

If the property has read access only, you can use the @property-read 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.

Loading history...
195
                ]
196
            );
197
198
            DB::beginTransaction();
199
200
            if ($akademik->save() && $nilai->save())
201
            {
202
                DB::commit();
203
204
                $error      = false;
205
                $message    = 'Success';
206
            } else {
207
                DB::rollBack();
208
209
                $error      = true;
210
                $message    = 'Failed';
211
            }
212
        }
213
214
        $response['akademik']   = $akademik;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$response was never initialized. Although not strictly required by PHP, it is generally a good practice to add $response = array(); before regardless.

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

Let’s take a look at an example:

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

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

    // do something with $myArray
}

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

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

Loading history...
215
        $response['error']      = $error;
216
        $response['message']    = $message;
217
        $response['status']     = true;
218
219
        return response()->json($response);
220
    }
221
222
    /**
223
     * Display the specified resource.
224
     *
225
     * @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 $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...
226
     * @return \Illuminate\Http\Response
227
     */
228 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...
229
    {
230
        $akademik = $this->akademik->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

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
231
232
        $response['akademik']   = $akademik;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$response was never initialized. Although not strictly required by PHP, it is generally a good practice to add $response = array(); before regardless.

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

Let’s take a look at an example:

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

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

    // do something with $myArray
}

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

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

Loading history...
233
        $response['error']      = false;
234
        $response['message']    = 'Success';
235
        $response['status']     = true;
236
237
        return response()->json($response);
238
    }
239
240
    /**
241
     * Show the form for editing the specified resource.
242
     *
243
     * @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 $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...
244
     * @return \Illuminate\Http\Response
245
     */
246 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...
247
    {
248
        $user_id        = isset(Auth::User()->id) ? Auth::User()->id : null;
249
        $akademik       = $this->akademik->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

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
250
        $siswas         = $this->siswa->getAttributes();
251
        $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 $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
252
        $users_special  = $this->user->all();
253
        $users_standar  = $this->user->findOrFail($user_id);
254
        $current_user   = Auth::User();
255
256
        if ($akademik->siswa !== null) {
257
            array_set($akademik->siswa, 'label', $akademik->siswa->nomor_un.' - '.$akademik->siswa->nama_siswa);
258
        }
259
260
        $role_check = Auth::User()->hasRole(['superadministrator','administrator']);
261
262
        if ($akademik->user !== null) {
263
            array_set($akademik->user, 'label', $akademik->user->name);
264
        }
265
266
        if ($role_check) {
267
            $user_special = true;
268
269
            foreach($users_special as $user){
270
                array_set($user, 'label', $user->name);
271
            }
272
273
            $users = $users_special;
274
        } else {
275
            $user_special = false;
276
277
            array_set($users_standar, 'label', $users_standar->name);
278
279
            $users = $users_standar;
280
        }
281
282
        array_set($current_user, 'label', $current_user->name);
283
284
        $response['akademik']       = $akademik;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$response was never initialized. Although not strictly required by PHP, it is generally a good practice to add $response = array(); before regardless.

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

Let’s take a look at an example:

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

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

    // do something with $myArray
}

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

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

Loading history...
285
        $response['siswas']         = $siswas;
286
        $response['users']          = $users;
287
        $response['user_special']   = $user_special;
288
        $response['current_user']   = $current_user;
289
        $response['error']          = false;
290
        $response['message']        = 'Success';
291
        $response['status']         = true;
292
293
        return response()->json($response);
294
    }
295
296
    /**
297
     * Update the specified resource in storage.
298
     *
299
     * @param  \Illuminate\Http\Request  $request
300
     * @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 $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...
301
     * @return \Illuminate\Http\Response
302
     */
303
    public function update(Request $request, $id)
304
    {
305
        $akademik = $this->akademik->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

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
306
307
        $validator = Validator::make($request->all(), [
308
            // 'nomor_un'          => "required|exists:{$this->siswa->getTable()},nomor_un|unique:{$this->akademik->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.

Loading history...
309
            'bahasa_indonesia'  => 'required|numeric|min:0|max:100',
310
            'bahasa_inggris'    => 'required|numeric|min:0|max:100',
311
            'matematika'        => 'required|numeric|min:0|max:100',
312
            'ipa'               => 'required|numeric|min:0|max:100',
313
            'user_id'           => "required|exists:{$this->user->getTable()},id",
314
        ]);
315
316 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.

Loading history...
317
            $error      = true;
318
            $message    = $validator->errors()->first();
319
        } else {
320
            $akademik->nomor_un         = $akademik->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.

Loading history...
321
            $akademik->bahasa_indonesia = $request->input('bahasa_indonesia');
322
            $akademik->bahasa_inggris   = $request->input('bahasa_inggris');
323
            $akademik->matematika       = $request->input('matematika');
324
            $akademik->ipa              = $request->input('ipa');
325
            $akademik->user_id          = $request->input('user_id');
326
327
            $nilai = $this->nilai->updateOrCreate(
0 ignored issues
show
Documentation Bug introduced by
The method updateOrCreate does not exist on object<Bantenprov\Nilai\...Bantenprov\Nilai\Nilai>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

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 { }
Loading history...
328
                [
329
                    'nomor_un'  => $akademik->nomor_un,
330
                ],
331
                [
332
                    'nomor_un'  => $akademik->nomor_un,
333
                    'bobot'     => $akademik->calcNilaiBobot($request),
334
                    'akademik'  => $akademik->calcNilaiAkademik($request),
335
                    'total'     => null,
336
                    'user_id'   => $akademik->user_id,
337
                ]
338
            );
339
340
            DB::beginTransaction();
341
342
            if ($akademik->save() && $nilai->save())
343
            {
344
                DB::commit();
345
346
                $error      = false;
347
                $message    = 'Success';
348
            } else {
349
                DB::rollBack();
350
351
                $error      = true;
352
                $message    = 'Failed';
353
            }
354
        }
355
356
        $response['akademik']   = $akademik;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$response was never initialized. Although not strictly required by PHP, it is generally a good practice to add $response = array(); before regardless.

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

Let’s take a look at an example:

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

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

    // do something with $myArray
}

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

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

Loading history...
357
        $response['error']      = $error;
358
        $response['message']    = $message;
359
        $response['status']     = true;
360
361
        return response()->json($response);
362
    }
363
364
    /**
365
     * Remove the specified resource from storage.
366
     *
367
     * @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 $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...
368
     * @return \Illuminate\Http\Response
369
     */
370 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...
371
    {
372
        $akademik = $this->akademik->findOrFail($id);
0 ignored issues
show
Documentation Bug introduced by
The method findOrFail does not exist on object<Bantenprov\Nilai\...tenprov\Nilai\Akademik>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

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 { }
Loading history...
373
374
        if ($akademik->delete()) {
375
            $response['message']    = 'Success';
0 ignored issues
show
Coding Style Comprehensibility introduced by
$response was never initialized. Although not strictly required by PHP, it is generally a good practice to add $response = array(); before regardless.

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

Let’s take a look at an example:

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

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

    // do something with $myArray
}

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

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

Loading history...
376
            $response['success']    = true;
377
            $response['status']     = true;
378
        } else {
379
            $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 $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...
380
            $response['success']    = false;
381
            $response['status']     = false;
382
        }
383
384
        return json_encode($response);
385
    }
386
}
387