Completed
Push — master ( bde2da...1c4382 )
by
unknown
9s
created

SeleksiController::update()   B

Complexity

Conditions 6
Paths 7

Size

Total Lines 50
Code Lines 33

Duplication

Lines 18
Ratio 36 %

Importance

Changes 0
Metric Value
cc 6
eloc 33
nc 7
nop 2
dl 18
loc 50
rs 8.6315
c 0
b 0
f 0
1
<?php
2
3
namespace Bantenprov\Seleksi\Http\Controllers;
4
5
/* Require */
6
use App\Http\Controllers\Controller;
7
use Illuminate\Http\Request;
8
9
/* Models */
10
use Bantenprov\Seleksi\Models\Bantenprov\Seleksi\Seleksi;
11
use Bantenprov\Pendaftaran\Models\Bantenprov\Pendaftaran\Pendaftaran;
12
use Bantenprov\Siswa\Models\Bantenprov\Siswa\Siswa;
13
use Bantenprov\Nilai\Models\Bantenprov\Nilai\Nilai;
14
use App\User;
15
16
/* Etc */
17
use Validator;
18
19
/**
20
 * The SeleksiController class.
21
 *
22
 * @package Bantenprov\Seleksi
23
 * @author  bantenprov <[email protected]>
24
 */
25
class SeleksiController extends Controller
26
{
27
    /**
28
     * Create a new controller instance.
29
     *
30
     * @return void
31
     */
32
    protected $pendaftaran;
33
    protected $seleksi;
34
    protected $siswa;
35
    protected $nilai;
36
    protected $user;
37
38
    public function __construct(Seleksi $seleksi, Pendaftaran $pendaftaran, User $user, Siswa $siswa, Nilai $nilai)
39
    {
40
        $this->seleksi        = $seleksi;
41
        $this->pendaftaran    = $pendaftaran;
42
        $this->user           = $user;
43
        $this->siswa          = $siswa;
44
        $this->nilai          = $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->seleksi->with('pendaftaran')->with('user')->with('siswa')->with('nilai')->orderBy($sortCol, $sortDir);
58
        } else {
59
            $query = $this->seleksi->with('pendaftaran')->with('user')->with('siswa')->with('nilai')->orderBy('id', 'asc');
60
        }
61
62
        if ($request->exists('filter')) {
63
            $query->where(function($q) use($request) {
64
                $value = "%{$request->filter}%";
65
                $q->where('nilai_id', 'like', $value)
66
                    ->orWhere('pendaftaran_id', 'like', $value);
67
            });
68
        }
69
70
        $perPage = request()->has('per_page') ? (int) request()->per_page : null;
71
        $response = $query->paginate($perPage);
72
73
        return response()->json($response)
74
            ->header('Access-Control-Allow-Origin', '*')
75
            ->header('Access-Control-Allow-Methods', 'GET');
76
    }
77
78
    /**
79
     * Show the form for creating a new resource.
80
     *
81
     * @return \Illuminate\Http\Response
82
     */
83
    public function create()
84
    {
85
        $response = [];
86
87
        $pendaftarans = $this->pendaftaran->all();
88
        $siswas = $this->siswa->all();
89
        $nilais = $this->nilai->all();
90
        $users_special = $this->user->all();
91
        $users_standar = $this->user->find(\Auth::User()->id);
92
        $current_user = \Auth::User();
93
94
        $role_check = \Auth::User()->hasRole(['superadministrator','administrator']);
95
96
        if($role_check){
97
            $response['user_special'] = true;
98
            foreach($users_special as $user){
99
                array_set($user, 'label', $user->name);
100
            }
101
            $response['user'] = $users_special;
102
        }else{
103
            $response['user_special'] = false;
104
            array_set($users_standar, 'label', $users_standar->name);
105
            $response['user'] = $users_standar;
106
        }
107
108
        array_set($current_user, 'label', $current_user->name);
109
110
        foreach($pendaftarans as $pendaftaran){
111
            array_set($pendaftaran, 'label', $pendaftaran->kegiatan->label);
112
        }
113
114
115
        foreach($nilais as $nilai){
116
            array_set($nilai, 'label', $nilai->siswa->nomor_un.' - '.$nilai->siswa->nama_siswa);
117
        }
118
119
        $response['current_user'] = $current_user;
120
        $response['pendaftaran'] = $pendaftarans;
121
        $response['siswa'] = $siswas;
122
        $response['nilai'] = $nilais;
123
        $response['status'] = true;
124
125
        return response()->json($response);
126
    }
127
128
    /**
129
     * Display the specified resource.
130
     *
131
     * @param  \App\Seleksi  $seleksi
0 ignored issues
show
Bug introduced by
There is no parameter named $seleksi. 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...
132
     * @return \Illuminate\Http\Response
133
     */
134
    public function store(Request $request)
135
    {
136
        $seleksi = $this->seleksi;
137
        $current_user_id = $request->user_id;
138
139
        $validator = Validator::make($request->all(), [
140
            'pendaftaran_id' => 'required',
141
            'user_id' => 'required',
142
            'nilai_id' => 'required|unique:seleksis,nilai_id',
143
            'nomor_un' => 'required|unique:seleksis,nomor_un'
144
        ]);
145
146
        if($validator->fails()){
147
148
            $check = $seleksi->Where('nilai_id', $request->nilai_id)->orWhere('nomor_un', $request->nomor_un)->whereNull('deleted_at')->count();
0 ignored issues
show
Documentation Bug introduced by
The method Where does not exist on object<Bantenprov\Seleks...enprov\Seleksi\Seleksi>? 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...
149
150
            if ($check > 0) {
151
                $response['message'] = 'Failed,  Nama Siswa already exists';
0 ignored issues
show
Coding Style Comprehensibility introduced by
$response was never initialized. Although not strictly required by PHP, it is generally a good practice to add $response = array(); before regardless.

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

Let’s take a look at an example:

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

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

    // do something with $myArray
}

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

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

Loading history...
152
            } else {
153
                $seleksi->pendaftaran_id = $request->input('pendaftaran_id');
0 ignored issues
show
Documentation introduced by
The property pendaftaran_id does not exist on object<Bantenprov\Seleks...enprov\Seleksi\Seleksi>. 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...
154
                $seleksi->user_id = $current_user_id;
0 ignored issues
show
Documentation introduced by
The property user_id does not exist on object<Bantenprov\Seleks...enprov\Seleksi\Seleksi>. 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...
155
                $seleksi->nomor_un = $request->input('nomor_un');
0 ignored issues
show
Documentation introduced by
The property nomor_un does not exist on object<Bantenprov\Seleks...enprov\Seleksi\Seleksi>. 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...
156
                $seleksi->nilai_id = $request->input('nilai_id');
0 ignored issues
show
Documentation introduced by
The property nilai_id does not exist on object<Bantenprov\Seleks...enprov\Seleksi\Seleksi>. 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...
157
                $seleksi->save();                
158
159
                $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...
160
            }
161
        } else {
162
            $seleksi->pendaftaran_id = $request->input('pendaftaran_id');
0 ignored issues
show
Documentation introduced by
The property pendaftaran_id does not exist on object<Bantenprov\Seleks...enprov\Seleksi\Seleksi>. 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...
163
            $seleksi->user_id = $current_user_id;
0 ignored issues
show
Documentation introduced by
The property user_id does not exist on object<Bantenprov\Seleks...enprov\Seleksi\Seleksi>. 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...
164
            $seleksi->nomor_un = $request->input('nomor_un');
0 ignored issues
show
Documentation introduced by
The property nomor_un does not exist on object<Bantenprov\Seleks...enprov\Seleksi\Seleksi>. 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...
165
            $seleksi->nilai_id = $request->input('nilai_id');
0 ignored issues
show
Documentation introduced by
The property nilai_id does not exist on object<Bantenprov\Seleks...enprov\Seleksi\Seleksi>. 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...
166
            $seleksi->save();
167
            $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...
168
        }
169
170
        $response['status'] = true;
171
172
        return response()->json($response);
173
    }
174
175
    /**
176
     * Store a newly created resource in storage.
177
     *
178
     * @param  \Illuminate\Http\Request  $request
0 ignored issues
show
Bug introduced by
There is no parameter named $request. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
179
     * @return \Illuminate\Http\Response
180
     */
181
    public function show($id)
182
    {
183
        $seleksi = $this->seleksi->findOrFail($id);
0 ignored issues
show
Documentation Bug introduced by
The method findOrFail does not exist on object<Bantenprov\Seleks...enprov\Seleksi\Seleksi>? 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...
184
185
        $response['seleksi'] = $seleksi;
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...
186
        $response['pendaftaran'] = $seleksi->pendaftaran;
187
        $response['user'] = $seleksi->user;
188
        $response['siswa'] = $seleksi->siswa;
189
        $response['nilai'] = $seleksi->nilai;
190
        $response['status'] = true;
191
192
        return response()->json($response);
193
    }
194
195
    /**
196
     * Show the form for editing the specified resource.
197
     *
198
     * @param  \App\Seleksi  $seleksi
0 ignored issues
show
Bug introduced by
There is no parameter named $seleksi. 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...
199
     * @return \Illuminate\Http\Response
200
     */
201
    public function edit($id)
202
    {
203
        $seleksi = $this->seleksi->with(['pendaftaran', 'nilai', 'siswa', 'user'])->findOrFail($id);
0 ignored issues
show
Bug introduced by
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...
204
205
206
        array_set($seleksi->user, 'label', $seleksi->user->name);
207
        array_set($seleksi->pendaftaran, 'label', $seleksi->pendaftaran->kegiatan->label);
208
             
209
        
210
            /*array_set($seleksi->nilai, 'label', $seleksi->nilai->nomor_un.' - '.$seleksi->nilai->siswa->nama_siswa);*/
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% 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...
211
    
212
213
214
        $response['seleksi'] = $seleksi;
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['pendaftaran'] = $seleksi->pendaftaran;
216
        $response['user'] = $seleksi->user;
217
        $response['siswa'] = $seleksi->siswa;
218
        $response['nilai'] = $seleksi->nilai;
219
        $response['status'] = true;
220
221
        return response()->json($response);
222
    }
223
224
    /**
225
     * Update the specified resource in storage.
226
     *
227
     * @param  \Illuminate\Http\Request  $request
228
     * @param  \App\Seleksi  $seleksi
0 ignored issues
show
Bug introduced by
There is no parameter named $seleksi. 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...
229
     * @return \Illuminate\Http\Response
230
     */
231
    public function update(Request $request, $id)
232
    {
233
234
        $response = array();
235
        $message  = array();
236
        $seleksi = $this->seleksi->findOrFail($id);
0 ignored issues
show
Documentation Bug introduced by
The method findOrFail does not exist on object<Bantenprov\Seleks...enprov\Seleksi\Seleksi>? 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...
237
238
            $validator = Validator::make($request->all(), [
239
                'user_id' => 'required',
240
                'pendaftaran_id' => 'required',
241
                'nomor_un' => 'required|unique:seleksis,nomor_un,'.$id,
242
                'nilai_id' => 'required|unique:seleksis,nilai_id,'.$id,
243
            ]);
244
245
        if ($validator->fails()) {
246
247
            foreach($validator->messages()->getMessages() as $key => $error){
248
                        foreach($error AS $error_get) {
249
                            array_push($message, $error_get);
250
                        }
251
                    }
252
253
             $check_siswa = $this->seleksi->where('id','!=', $id)->where('nomor_un', $request->nomor_un);
0 ignored issues
show
Documentation Bug introduced by
The method where does not exist on object<Bantenprov\Seleks...enprov\Seleksi\Seleksi>? 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...
254
             $check_nilai = $this->seleksi->where('id','!=', $id)->where('nilai_id', $request->nilai_id);
0 ignored issues
show
Documentation Bug introduced by
The method where does not exist on object<Bantenprov\Seleks...enprov\Seleksi\Seleksi>? 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...
255
256
             if($check_siswa->count() > 0 || $check_nilai->count() > 0){
257
                  $response['message'] = implode("\n",$message);
258 View Code Duplication
            } else {
0 ignored issues
show
Duplication introduced by
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...
259
                $seleksi->user_id = $request->input('user_id');
260
                $seleksi->pendaftaran_id = $request->input('pendaftaran_id');
261
                $seleksi->nomor_un = $request->input('nomor_un');
262
                $seleksi->nilai_id = $request->input('nilai_id');
263
                $seleksi->save();
264
265
                $response['message'] = 'success';
266
            }
267 View Code Duplication
        } else {
0 ignored issues
show
Duplication introduced by
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...
268
            $seleksi->user_id = $request->input('user_id');
269
                $seleksi->pendaftaran_id = $request->input('pendaftaran_id');
270
                $seleksi->nomor_un = $request->input('nomor_un');
271
                $seleksi->nilai_id = $request->input('nilai_id');
272
                $seleksi->save();
273
274
            $response['message'] = 'success';
275
        }
276
277
        $response['status'] = true;
278
279
        return response()->json($response);
280
    }
281
282
    /**
283
     * Remove the specified resource from storage.
284
     *
285
     * @param  \App\Seleksi  $seleksi
0 ignored issues
show
Bug introduced by
There is no parameter named $seleksi. 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...
286
     * @return \Illuminate\Http\Response
287
     */
288
    public function destroy($id)
289
    {
290
        $seleksi = $this->seleksi->findOrFail($id);
0 ignored issues
show
Documentation Bug introduced by
The method findOrFail does not exist on object<Bantenprov\Seleks...enprov\Seleksi\Seleksi>? 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...
291
292
        if ($seleksi->delete()) {
293
            $response['status'] = true;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$response was never initialized. Although not strictly required by PHP, it is generally a good practice to add $response = array(); before regardless.

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

Let’s take a look at an example:

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

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

    // do something with $myArray
}

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

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

Loading history...
294
        } else {
295
            $response['status'] = false;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$response was never initialized. Although not strictly required by PHP, it is generally a good practice to add $response = array(); before regardless.

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

Let’s take a look at an example:

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

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

    // do something with $myArray
}

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

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

Loading history...
296
        }
297
298
        return json_encode($response);
299
    }
300
}