Completed
Push — master ( ad81a8...20ded6 )
by
unknown
03:07 queued 01:18
created

PendaftaranController::update()   D

Complexity

Conditions 14
Paths 28

Size

Total Lines 94
Code Lines 71

Duplication

Lines 24
Ratio 25.53 %

Importance

Changes 0
Metric Value
cc 14
eloc 71
nc 28
nop 2
dl 24
loc 94
rs 4.9516
c 0
b 0
f 0

How to fix   Long Method    Complexity   

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\Pendaftaran\Http\Controllers;
4
5
/* Require */
6
use App\Http\Controllers\Controller;
7
use Illuminate\Http\Request;
8
use Bantenprov\BudgetAbsorption\Facades\PendaftaranFacade;
9
use Bantenprov\VueWorkflow\Http\Traits\WorkflowTrait;
10
11
/* Models */
12
use Bantenprov\Pendaftaran\Models\Bantenprov\Pendaftaran\Pendaftaran;
13
use Bantenprov\Kegiatan\Models\Bantenprov\Kegiatan\Kegiatan;
14
use App\User;
15
16
/* Etc */
17
use Validator;
18
19
/**
20
 * The PendaftaranController class.
21
 *
22
 * @package Bantenprov\Pendaftaran
23
 * @author  bantenprov <[email protected]>
24
 */
25
class PendaftaranController extends Controller
26
{  
0 ignored issues
show
Coding Style introduced by
The opening class brace should be on a newline by itself.
Loading history...
27
    use WorkflowTrait;
28
    /**
29
     * Create a new controller instance.
30
     *
31
     * @return void
32
     */
33
    protected $kegiatanModel;
34
    protected $pendaftaran;
35
    protected $user;
36
37
    public function __construct(Pendaftaran $pendaftaran, Kegiatan $kegiatan, User $user)
38
    {
39
        $this->pendaftaran      = $pendaftaran;
40
        $this->kegiatanModel    = $kegiatan;
41
        $this->user             = $user;
42
    }
43
44
    /**
45
     * Display a listing of the resource.
46
     *
47
     * @return \Illuminate\Http\Response
48
     */
49
    public function index(Request $request)
50
    {
51
        if (request()->has('sort')) {
52
            list($sortCol, $sortDir) = explode('|', request()->sort);
53
54
            $query = $this->pendaftaran->with('kegiatan')->with('user')->orderBy($sortCol, $sortDir);
55
        } else {
56
            $query = $this->pendaftaran->with('kegiatan')->with('user')->orderBy('id', 'asc');
57
        }
58
59
        if ($request->exists('filter')) {
60
            $query->where(function($q) use($request) {
61
                $value = "%{$request->filter}%";
62
                $q->where('label', 'like', $value)
63
                    ->orWhere('description', 'like', $value);
64
            });
65
        }
66
67
        $perPage = request()->has('per_page') ? (int) request()->per_page : null;
68
        $response = $query->paginate($perPage);
69
70
        return response()->json($response)
71
            ->header('Access-Control-Allow-Origin', '*')
72
            ->header('Access-Control-Allow-Methods', 'GET');
73
    }
74
75
    /**
76
     * Show the form for creating a new resource.
77
     *
78
     * @return \Illuminate\Http\Response
79
     */
80
    public function create()
81
    {
82
        $kegiatan = $this->kegiatanModel->all();
83
        $users_special = $this->user->all();
84
        $users_standar = $this->user->find(\Auth::User()->id);
85
        
86
        $role_check = \Auth::User()->hasRole(['superadministrator','administrator']);
87
88
        if($role_check){
89
            $response['user_special'] = 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...
90
            foreach($users_special as $user){
91
                array_set($user, 'label', $user->name);
92
            }
93
            $response['user'] = $users_special;
94
        }else{
95
            $response['user_special'] = 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...
96
            array_set($users_standar, 'label', $users_standar->name);
97
            $response['user'] = $users_standar;
98
        } 
99
100
        $response['kegiatan'] = $kegiatan;        
101
        $response['status'] = true;
102
103
        return response()->json($response);
104
    }
105
106
    /**
107
     * Display the specified resource.
108
     *
109
     * @param  \App\Pendaftaran  $pendaftaran
0 ignored issues
show
Bug introduced by
There is no parameter named $pendaftaran. 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...
110
     * @return \Illuminate\Http\Response
111
     */
112
    public function store(Request $request)
113
    {
114
        $pendaftaran = $this->pendaftaran;
115
116
        $validator = Validator::make($request->all(), [
117
            'kegiatan_id' => 'required',
118
            'user_id' => 'required|max:16|unique:pendaftarans,user_id',
119
            'label' => 'required|max:16|unique:pendaftarans,label',
120
            'description' => 'max:255',
121
        ]);
122
123
        if($validator->fails()){
124
125
            $check = $pendaftaran->where('label',$request->label)->orWhere('user_id', $request->user_id)->whereNull('deleted_at')->count();
126
127 View Code Duplication
            if ($check > 0) {
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...
128
                $response['message'] = 'Failed, label or user 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...
129
            } else {
130
                $pendaftaran->kegiatan_id = $request->input('kegiatan_id');
131
                $pendaftaran->user_id = $request->input('user_id');
132
                $pendaftaran->label = $request->input('label');
133
                $pendaftaran->description = $request->input('description');                
134
                $pendaftaran->save();
135
136
                $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...
137
            }
138
        } else {
139
            $pendaftaran->kegiatan_id = $request->input('kegiatan_id');
140
            $pendaftaran->user_id = $request->input('user_id');
141
            $pendaftaran->label = $request->input('label');
142
            $pendaftaran->description = $request->input('description');            
143
            $pendaftaran->save();
144
            $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...
145
        }
146
147
        $response['status'] = true;
148
149
        return response()->json($response);
150
    }
151
152
    /**
153
     * Store a newly created resource in storage.
154
     *
155
     * @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...
156
     * @return \Illuminate\Http\Response
157
     */
158
    public function show($id)
159
    {
160
        $pendaftaran = $this->pendaftaran->findOrFail($id);
161
162
        $response['pendaftaran'] = $pendaftaran;
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
        $response['kegiatan'] = $pendaftaran->kegiatan;
164
        $response['user'] = $pendaftaran->user;
165
        $response['status'] = true;
166
167
        return response()->json($response);
168
    }
169
170
    /**
171
     * Show the form for editing the specified resource.
172
     *
173
     * @param  \App\Pendaftaran  $pendaftaran
0 ignored issues
show
Bug introduced by
There is no parameter named $pendaftaran. 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...
174
     * @return \Illuminate\Http\Response
175
     */
176
    public function edit($id)
177
    {
178
        $pendaftaran = $this->pendaftaran->findOrFail($id);
179
180
        array_set($pendaftaran->user, 'label', $pendaftaran->user->name);
181
182
        $response['pendaftaran'] = $pendaftaran;
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...
183
        $response['kegiatan'] = $pendaftaran->kegiatan;
184
        $response['user'] = $pendaftaran->user;
185
        $response['status'] = true;
186
187
        return response()->json($response);
188
    }
189
190
    /**
191
     * Update the specified resource in storage.
192
     *
193
     * @param  \Illuminate\Http\Request  $request
194
     * @param  \App\Pendaftaran  $pendaftaran
0 ignored issues
show
Bug introduced by
There is no parameter named $pendaftaran. 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...
195
     * @return \Illuminate\Http\Response
196
     */
197
    public function update(Request $request, $id)
198
    {                
199
        $pendaftaran = $this->pendaftaran->findOrFail($id);
200
201
        if($request->old_label == $request->label && $request->user_id != $request->old_user_id){
202
            $validator = Validator::make($request->all(), [
203
                'label' => 'required',
204
                'description' => 'max:255',
205
                'kegiatan_id' => 'required',
206
                'user_id' => 'required|unique:pendaftarans,user_id',
207
            ]);
208
            $fail = "user_id";
209
        }elseif($request->old_label != $request->label && $request->user_id == $request->old_user_id){
210
            $validator = Validator::make($request->all(), [
211
                'label' => 'required|unique:pendaftarans,label',
212
                'description' => 'max:255',
213
                'kegiatan_id' => 'required',
214
                'user_id' => 'required',
215
            ]);
216
            $fail = "label";
217
        }elseif($request->old_label == $request->label && $request->user_id == $request->old_user_id){
218
            $validator = Validator::make($request->all(), [
219
                'label' => 'required',
220
                'description' => 'max:255',
221
                'kegiatan_id' => 'required',
222
                'user_id' => 'required',
223
            ]);
224
        }else{
225
            $validator = Validator::make($request->all(), [
226
                'label' => 'required|unique:pendaftarans,label',
227
                'description' => 'max:255',
228
                'kegiatan_id' => 'required',
229
                'user_id' => 'required|unique:pendaftarans,label',
230
            ]);
231
            $fail = "label & user_id";
232
        }
233
234
        if ($validator->fails()) {
235
236
            $check_user = $pendaftaran->where('user_id', $request->user_id)->whereNull('deleted_at')->count();
237
238
            $check_label = $pendaftaran->where('label',$request->label)->whereNull('deleted_at')->count();
239
240
            if($fail == "label"){
241 View Code Duplication
                if ($check_label > 0) {                    
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...
242
                    $response['message'] = 'Failed, label 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...
243
                }else{
244
                    $pendaftaran->label = $request->input('label');
245
                    $pendaftaran->description = $request->input('description');
246
                    $pendaftaran->kegiatan_id = $request->input('kegiatan_id');
247
                    $pendaftaran->user_id = $request->input('user_id');
248
                    $pendaftaran->save();
249
250
                    $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...
251
                }
252 View Code Duplication
            }elseif($fail == "user_id"){
0 ignored issues
show
Bug introduced by
The variable $fail does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
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...
253
                if ($check_user > 0) {                    
254
                    $response['message'] = 'Failed, user 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...
255
                }else{
256
                    $pendaftaran->label = $request->input('label');
257
                    $pendaftaran->description = $request->input('description');
258
                    $pendaftaran->kegiatan_id = $request->input('kegiatan_id');
259
                    $pendaftaran->user_id = $request->input('user_id');
260
                    $pendaftaran->save();
261
262
                    $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...
263
                }
264
            }else{
265
                if ($check_user > 0 && $check_label > 0) {                    
266
                    $response['message'] = 'Failed, user and label 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...
267
                }else{
268
                    $pendaftaran->label = $request->input('label');
269
                    $pendaftaran->description = $request->input('description');
270
                    $pendaftaran->kegiatan_id = $request->input('kegiatan_id');
271
                    $pendaftaran->user_id = $request->input('user_id');
272
                    $pendaftaran->save();
273
274
                    $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...
275
                }
276
            }                       
277
        } else {
278
            $pendaftaran->label = $request->input('label');
279
            $pendaftaran->description = $request->input('description');
280
            $pendaftaran->kegiatan_id = $request->input('kegiatan_id');
281
            $pendaftaran->user_id = $request->input('user_id');
282
            $pendaftaran->save();
283
284
            $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...
285
        }
286
287
        $response['status'] = true;
288
289
        return response()->json($response);
290
    }
291
292
    /**
293
     * Remove the specified resource from storage.
294
     *
295
     * @param  \App\Pendaftaran  $pendaftaran
0 ignored issues
show
Bug introduced by
There is no parameter named $pendaftaran. 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...
296
     * @return \Illuminate\Http\Response
297
     */
298
    public function destroy($id)
299
    {
300
        $pendaftaran = $this->pendaftaran->findOrFail($id);
301
302
        if ($pendaftaran->delete()) {
303
            $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...
304
        } else {
305
            $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...
306
        }
307
308
        return json_encode($response);
309
    }
310
}
311