Completed
Push — master ( b76649...5832b1 )
by
unknown
8s
created

SeleksiController::update()   C

Complexity

Conditions 7
Paths 7

Size

Total Lines 51
Code Lines 34

Duplication

Lines 18
Ratio 35.29 %

Importance

Changes 0
Metric Value
cc 7
eloc 34
nc 7
nop 2
dl 18
loc 51
rs 6.9743
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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->description);
112
        }
113
114
        foreach($siswas as $siswa){
115
            array_set($siswa, 'label', $siswa->nama_siswa);
116
        }
117
118
        foreach($nilais as $nilai){
119
            array_set($nilai, 'label', $nilai->siswa->nama_siswa);
120
        }
121
122
        $response['current_user'] = $current_user;
123
        $response['pendaftaran'] = $pendaftarans;
124
        $response['siswa'] = $siswas;
125
        $response['nilai'] = $nilais;
126
        $response['status'] = true;
127
128
        return response()->json($response);
129
    }
130
131
    /**
132
     * Display the specified resource.
133
     *
134
     * @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...
135
     * @return \Illuminate\Http\Response
136
     */
137
    public function store(Request $request)
138
    {
139
        $seleksi = $this->seleksi;
140
        $current_user_id = $request->user_id;
141
142
        $validator = Validator::make($request->all(), [
143
            'pendaftaran_id' => 'required|unique:seleksis,pendaftaran_id',
144
            'user_id' => 'required',
145
            'nilai_id' => 'required|unique:seleksis,nilai_id',
146
            'nomor_un' => 'required|unique:seleksis,nomor_un'
147
        ]);
148
149
        if($validator->fails()){
150
151
            $check = $seleksi->where('pendaftaran_id', $request->pendaftaran_id)->orWhere('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...
152
153
            if ($check > 0) {
154
                $response['message'] = 'Failed, Pendaftaran, Nama Siswa, Nilai 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...
155
            } else {
156
                $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...
157
                $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...
158
                $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...
159
                $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...
160
                $seleksi->save();                
161
162
                $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...
163
            }
164
        } else {
165
            $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...
166
            $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...
167
            $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...
168
            $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...
169
            $seleksi->save();
170
            $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...
171
        }
172
173
        $response['status'] = true;
174
175
        return response()->json($response);
176
    }
177
178
    /**
179
     * Store a newly created resource in storage.
180
     *
181
     * @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...
182
     * @return \Illuminate\Http\Response
183
     */
184
    public function show($id)
185
    {
186
        $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...
187
188
        $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...
189
        $response['pendaftaran'] = $seleksi->pendaftaran;
190
        $response['user'] = $seleksi->user;
191
        $response['siswa'] = $seleksi->siswa;
192
        $response['nilai'] = $seleksi->nilai;
193
        $response['status'] = true;
194
195
        return response()->json($response);
196
    }
197
198
    /**
199
     * Show the form for editing the specified resource.
200
     *
201
     * @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...
202
     * @return \Illuminate\Http\Response
203
     */
204
    public function edit($id)
205
    {
206
        $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...
207
208
        array_set($seleksi->user, 'label', $seleksi->user->name);
209
        array_set($seleksi->pendaftaran, 'label', $seleksi->pendaftaran->kegiatan->description);
210
        array_set($seleksi->siswa, 'label', $seleksi->siswa->nama_siswa);
211
        array_set($seleksi->nilai, 'label', $seleksi->nilai->siswa->nama_siswa);
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|unique:seleksis,pendaftaran_id,'.$id,
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_pendaftaran = $this->seleksi->where('id','!=', $id)->where('pendaftaran_id', $request->pendaftaran_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...
254
             $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...
255
             $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...
256
257
             if($check_pendaftaran->count() > 0 || $check_siswa->count() > 0 || $check_nilai->count() > 0){
258
                  $response['message'] = implode("\n",$message);
259 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...
260
                $seleksi->user_id = $request->input('user_id');
261
                $seleksi->pendaftaran_id = $request->input('pendaftaran_id');
262
                $seleksi->nomor_un = $request->input('nomor_un');
263
                $seleksi->nilai_id = $request->input('nilai_id');
264
                $seleksi->save();
265
266
                $response['message'] = 'success';
267
            }
268 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...
269
            $seleksi->user_id = $request->input('user_id');
270
                $seleksi->pendaftaran_id = $request->input('pendaftaran_id');
271
                $seleksi->nomor_un = $request->input('nomor_un');
272
                $seleksi->nilai_id = $request->input('nilai_id');
273
                $seleksi->save();
274
275
            $response['message'] = 'success';
276
        }
277
278
        $response['status'] = true;
279
280
        return response()->json($response);
281
    }
282
283
    /**
284
     * Remove the specified resource from storage.
285
     *
286
     * @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...
287
     * @return \Illuminate\Http\Response
288
     */
289
    public function destroy($id)
290
    {
291
        $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...
292
293
        if ($seleksi->delete()) {
294
            $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...
295
        } else {
296
            $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...
297
        }
298
299
        return json_encode($response);
300
    }
301
}