Completed
Pull Request — master (#35)
by
unknown
01:20
created

PendaftaranController::show()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 113
Code Lines 50

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 50
nc 2
nop 1
dl 0
loc 113
rs 8.2857
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\Pendaftaran\Http\Controllers;
4
5
/* Require */
6
use App\Http\Controllers\Controller;
7
use Illuminate\Http\Request;
8
use Carbon\Carbon;
9
/* Models */
10
use Bantenprov\Pendaftaran\Models\Bantenprov\Pendaftaran\Pendaftaran;
11
use Bantenprov\Kegiatan\Models\Bantenprov\Kegiatan\Kegiatan;
12
use Bantenprov\Sekolah\Models\Bantenprov\Sekolah\Sekolah;
13
use Bantenprov\Sekolah\Models\Bantenprov\Sekolah\AdminSekolah;
14
use App\User;
15
use Bantenprov\Siswa\Models\Bantenprov\Siswa\Siswa;
16
use Bantenprov\Sktm\Models\Bantenprov\Sktm\MasterSktm;
17
use Bantenprov\Sktm\Models\Bantenprov\Sktm\Sktm;
18
use Bantenprov\Prestasi\Models\Bantenprov\Prestasi\JenisPrestasi;
19
use Bantenprov\Prestasi\Models\Bantenprov\Prestasi\MasterPrestasi;
20
use Bantenprov\Prestasi\Models\Bantenprov\Prestasi\Prestasi;
21
use Bantenprov\Prestasi\Http\Controllers\MasterPrestasiController;
22
23
/* Etc */
24
use Validator;
25
use Auth;
26
27
/**
28
 * The PendaftaranController class.
29
 *
30
 * @package Bantenprov\Pendaftaran
31
 * @author  bantenprov <[email protected]>
32
 */
33
class PendaftaranController extends Controller
34
{
35
    /**
36
     * Create a new controller instance.
37
     *
38
     * @return void
39
     */
40
    protected $kegiatanModel;
41
    protected $pendaftaran;
42
    protected $user;
43
    protected $sekolah;
44
    protected $admin_sekolah;
45
    protected $siswa;
46
    protected $mastersktm;
47
    protected $sktm;
48
    protected $jenisprestasi;
49
    protected $masterprestasi;
50
    protected $masterprestasicont;
51
    protected $prestasi;
52
53
    public function __construct()
54
    {
55
        $this->pendaftaran          = new Pendaftaran;
56
        $this->kegiatanModel        = new Kegiatan;
57
        $this->user                 = new User;
58
        $this->sekolah              = new Sekolah;
59
        $this->admin_sekolah        = new AdminSekolah;
60
        $this->siswa                = new Siswa;
61
        $this->sktm                 = new Sktm;
62
        $this->mastersktm           = new MasterSktm;
63
        $this->jenisprestasi        = new JenisPrestasi;
64
        $this->masterprestasi       = new MasterPrestasi;
65
        $this->masterprestasicont   = new MasterPrestasiController;
66
        $this->prestasi             = new Prestasi;
67
    }
68
69
    /**
70
     * Display a listing of the resource.
71
     *
72
     * @return \Illuminate\Http\Response
73
     */
74
    public function index(Request $request)
75
    {
76
        $admin_sekolah = $this->admin_sekolah->where('admin_sekolah_id', Auth::user()->id)->first();
77
78
        if(is_null($admin_sekolah) && $this->checkRole(['superadministrator']) === false){
79
            $response = [];
80
            return response()->json($response)
81
            ->header('Access-Control-Allow-Origin', '*')
82
            ->header('Access-Control-Allow-Methods', 'GET');
83
        }else{
84
            $page  					= 10;
85
            $data 					= $this->pendaftaran
86
                                    ->select(
87
                                        'pendaftarans.id',
88
                                        'users.name',
89
                                        'pendaftarans.tanggal_pendaftaran',
90
                                        'sekolahs.nama',
91
                                        'kegiatans.label',
92
                                        'siswas.nama_siswa'
93
                                    )
94
                                    ->leftjoin(
95
                                        'sekolahs',
96
                                        'pendaftarans.sekolah_id','=','sekolahs.id'
97
                                    )
98
                                    ->leftjoin(
99
                                        'kegiatans',
100
                                        'pendaftarans.kegiatan_id','=','kegiatans.id'
101
                                    )
102
                                    ->leftjoin(
103
                                        'users',
104
                                        'pendaftarans.user_id','=','users.id'
105
                                    )
106
                                    ->leftjoin(
107
                                        'siswas',
108
                                        'users.name','=','siswas.nomor_un'
109
                                    )
110
                                    ->where('pendaftarans.sekolah_id','=',$admin_sekolah->sekolah_id)
111
                                    ->paginate($page);
112
            return response()->json($data)
113
                ->header('Access-Control-Allow-Origin', '*')
114
                ->header('Access-Control-Allow-Methods', 'GET');            
115
        }
116
    }
117
118
    /**
119
     * Display the specified resource.
120
     *
121
     * @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...
122
     * @return \Illuminate\Http\Response
123
     */
124
    public function store(Request $request)
125
    {
126
        $admin_sekolah = $this->admin_sekolah->where('admin_sekolah_id', Auth::user()->id)->first();
127
128
        $pendaftaran        = $this->pendaftaran;
129
        $current_user_id    = $request->user_id;
130
131
        $validator = Validator::make($request->all(), [
132
            'kegiatan_id'           => 'required',
133
            'user_id'               => "required|exists:{$this->user->getTable()},id",
134
            'tanggal_pendaftaran'   => 'required',
135
            'sekolah_id'            => 'required',
136
        ]);
137
138
        if($admin_sekolah->sekolah_id != $request->sekolah_id && $this->checkRole(['superadministrator']) === false){
139
            $response['error']      = 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...
140
            $response['message']    = 'Terjadi kesalahan, mohon ulangi lagi pengisian data yang benar.';
141
            $response['status']     = true;
142
143
            return response()->json($response);
144
        }
145
146 View Code Duplication
        if ($validator->fails()) {
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...
147
            $error      = true;
148
            $message    = $validator->errors()->first();
149
150
            } else {
151
                $pendaftaran->kegiatan_id           = $request->input('kegiatan_id');
152
                $pendaftaran->user_id               = $current_user_id;
153
                $pendaftaran->tanggal_pendaftaran   = $request->input('tanggal_pendaftaran');
154
                $pendaftaran->sekolah_id            = $request->input('sekolah_id');
155
                $pendaftaran->save();
156
                $error      = false;
157
                $message    = 'Success';
158
            }
159
160
        $response['error']      = $error;
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...
161
        $response['message']    = $message;
162
        $response['status']     = true;
163
164
        return response()->json($response);
165
    }
166
167
    /**
168
     * Store a newly created resource in storage.
169
     *
170
     * @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...
171
     * @return \Illuminate\Http\Response
172
     */
173
    public function show($id)
174
    {
175
176
        // $admin_sekolah = $this->admin_sekolah->where('admin_sekolah_id', Auth::user()->id)->first();
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...
177
        // if($this->checkRole(['superadministrator'])){
0 ignored issues
show
Unused Code Comprehensibility introduced by
85% 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...
178
        //     $pendaftaran = $this->pendaftaran->findOrFail($id);
0 ignored issues
show
Unused Code Comprehensibility introduced by
58% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
179
        // }else{
180
        //     $pendaftaran = $this->pendaftaran->where('sekolah_id', $admin_sekolah->sekolah_id)->findOrFail($id);
0 ignored issues
show
Unused Code Comprehensibility introduced by
63% 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...
181
        // }
182
        
183
184
185
        $admin_sekolah = $this->admin_sekolah->where('admin_sekolah_id', Auth::user()->id)->first();
0 ignored issues
show
Unused Code introduced by
$admin_sekolah is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
186
187
        if($this->checkRole(['superadministrator'])){
0 ignored issues
show
Unused Code introduced by
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
188
//            $pendaftaran = $this->pendaftaran->findOrFail($id);
0 ignored issues
show
Unused Code Comprehensibility introduced by
58% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
189
        }else{
190
            $data 					= $this->pendaftaran
191
                                    ->select(
192
                                        'siswas.nama_siswa',
193
                                        'kegiatans.label as jenis_pendaftaran',
194
                                        'pendaftarans.id',
195
                                        'users.name',
196
                                        'pendaftarans.tanggal_pendaftaran',
197
                                        'sekolahs.nama as sekolah_tujuan',
198
                                        'master_sktms.nama as jenis_sktm',
199
                                        'sktms.no_sktm',
200
                                        'prestasis.nama_lomba',
201
                                        'jenis_prestasis.nama as jenis_prestasi',
202
                                        'master_prestasis.juara',
203
                                        'master_prestasis.tingkat'                                        
204
                                    )
205
                                    ->leftjoin(
206
                                        'sekolahs',
207
                                        'pendaftarans.sekolah_id','=','sekolahs.id'
208
                                    )
209
                                    ->leftjoin(
210
                                        'kegiatans',
211
                                        'pendaftarans.kegiatan_id','=','kegiatans.id'
212
                                    )
213
                                    ->leftjoin(
214
                                        'users',
215
                                        'pendaftarans.user_id','=','users.id'
216
                                    )
217
                                    ->leftjoin(
218
                                        'siswas',
219
                                        'users.name','=','siswas.nomor_un'
220
                                    )
221
                                    ->leftjoin(
222
                                        'sktms',
223
                                        'pendaftarans.nomor_un','=','sktms.nomor_un'
224
                                    )                                    
225
                                    ->leftjoin(
226
                                        'master_sktms',
227
                                        'sktms.master_sktm_id','=','master_sktms.id'
228
                                    )                                    
229
                                    ->leftjoin(
230
                                        'prestasis',
231
                                        'pendaftarans.nomor_un','=','prestasis.nomor_un'
232
                                    )
233
                                    ->leftjoin(
234
                                        'master_prestasis',
235
                                        'prestasis.master_prestasi_id','=','master_prestasis.id'
236
                                    )
237
                                    ->leftjoin(
238
                                        'jenis_prestasis',
239
                                        'master_prestasis.jenis_prestasi_id','=','jenis_prestasis.id'
240
                                    )
241
                                    ->where('pendaftarans.id','=',$id)
242
                                    ->first();
243
                // $result         = array();
0 ignored issues
show
Unused Code Comprehensibility introduced by
56% 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...
244
                // foreach((array)$data as $key => $val){
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% 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...
245
                //     if($key == '*attributes'){
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...
246
                //         dd($val);
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% 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...
247
                //         foreach($val as $key1 => $val1){
0 ignored issues
show
Unused Code Comprehensibility introduced by
65% 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...
248
                //             if($key1 == 'juara'){
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...
249
                //                 $result['juara']    = $this->masterprestasi->prestasi_label($val1);
0 ignored issues
show
Unused Code Comprehensibility introduced by
65% 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...
250
                //             }elseif($key1 == 'tingkat'){
0 ignored issues
show
Unused Code Comprehensibility introduced by
64% 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...
251
                //                 $result['tingkat']  = $this->masterprestasi->tingkat_label($val1);
0 ignored issues
show
Unused Code Comprehensibility introduced by
65% 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...
252
                //             }else{
253
                //                 $result[$key1]      = $val1;
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...
254
                //             }
255
                //         }
256
                //     }
257
                // }
258
                return response()->json($data)
259
                    ->header('Access-Control-Allow-Origin', '*')
260
                    ->header('Access-Control-Allow-Methods', 'GET');            
261
        }
262
263
        // $response['pendaftaran']    = $pendaftaran;
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...
264
        // $response['kegiatan']       = $pendaftaran->kegiatan;
0 ignored issues
show
Unused Code Comprehensibility introduced by
59% 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...
265
        // $response['sekolah']        = $pendaftaran->sekolah;
0 ignored issues
show
Unused Code Comprehensibility introduced by
59% 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...
266
        // $response['user']           = $pendaftaran->user;
0 ignored issues
show
Unused Code Comprehensibility introduced by
59% 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...
267
        // $response['siswa']          = $pendaftaran->siswa;
0 ignored issues
show
Unused Code Comprehensibility introduced by
59% 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...
268
        // /*
269
        // // $response['prestasi']       = $pendaftaran->sekolah;
270
        // // $response['sktm']          = $pendaftaran->sekolah;
271
        // */
272
273
        // $response['nama_siswa']             = $data->nama_siswa;
0 ignored issues
show
Unused Code Comprehensibility introduced by
59% 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...
274
        // $response['jenis_pendaftaran']      = $data->label;
0 ignored issues
show
Unused Code Comprehensibility introduced by
59% 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...
275
        // $response['sekolah_tujuan']         = $data->nama;
0 ignored issues
show
Unused Code Comprehensibility introduced by
59% 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...
276
        // $response['tanggal_pendaftaran']    = $data->tanggal_pendaftaran;
0 ignored issues
show
Unused Code Comprehensibility introduced by
59% 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...
277
        // $response['jenis_sktm']             = $data->nama;
0 ignored issues
show
Unused Code Comprehensibility introduced by
59% 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...
278
        // $response['no_sktm']                = $data->no_sktm;
0 ignored issues
show
Unused Code Comprehensibility introduced by
59% 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...
279
        // $response['prestasi']               = $data->nama_lomba;
0 ignored issues
show
Unused Code Comprehensibility introduced by
59% 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...
280
        // $response['jenis_prestasi']         = $data->nama;
0 ignored issues
show
Unused Code Comprehensibility introduced by
59% 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...
281
        // $response['juara']                  = $data->juara;
0 ignored issues
show
Unused Code Comprehensibility introduced by
59% 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...
282
        // $response['tingkat']                = $data->tingkat;
0 ignored issues
show
Unused Code Comprehensibility introduced by
59% 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...
283
        // $response['status']                 = true;
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...
284
        // return response()->json($response);
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% 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...
285
    }
286
287
    /**
288
     * Show the form for editing the specified resource.
289
     *
290
     * @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...
291
     * @return \Illuminate\Http\Response
292
     */
293
    public function edit($id)
294
    {
295
        $admin_sekolah = $this->admin_sekolah->where('admin_sekolah_id', Auth::user()->id)->first();
296
297
        if($this->checkRole(['superadministrator'])){
298
            $pendaftaran = $this->pendaftaran->with(['kegiatan', 'sekolah', 'user' ])->findOrFail($id);
299
        }else{
300
            $pendaftaran = $this->pendaftaran->where('sekolah_id', $admin_sekolah->sekolah_id)->with(['kegiatan', 'sekolah', 'user' ])->findOrFail($id);
301
        }
302
303
304
        $response['pendaftaran']['user']     = array_add($pendaftaran->user, 'label', $pendaftaran->user->name);
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...
305
306
307
308
        $response['pendaftaran']    = $pendaftaran;
309
        //$response['kegiatan']       = $pendaftaran->kegiatan;
0 ignored issues
show
Unused Code Comprehensibility introduced by
64% 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...
310
        //$response['sekolah']        = $pendaftaran->sekolah->nama;
0 ignored issues
show
Unused Code Comprehensibility introduced by
62% 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...
311
        //$response['user']           = $pendaftaran->user;
0 ignored issues
show
Unused Code Comprehensibility introduced by
64% 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...
312
        $response['error']          = false;
313
        $response['message']        = 'Success';
314
        $response['status']         = true;
315
316
        return response()->json($response);
317
    }
318
319
    /**
320
     * Update the specified resource in storage.
321
     *
322
     * @param  \Illuminate\Http\Request  $request
323
     * @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...
324
     * @return \Illuminate\Http\Response
325
     */
326
    public function update(Request $request, $id)
327
    {
328
        $admin_sekolah = $this->admin_sekolah->where('admin_sekolah_id', Auth::user()->id)->first();
329
330
        if($this->checkRole(['superadministrator'])){
331
            $pendaftaran = $this->pendaftaran->with(['kegiatan', 'sekolah', 'user' ])->findOrFail($id);
332
        }else{
333
            $pendaftaran = $this->pendaftaran->where('sekolah_id', $admin_sekolah->sekolah_id)->with(['kegiatan', 'sekolah', 'user' ])->findOrFail($id);
334
335
            if(is_null($pendaftaran)){
336
                $response['error']      = 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...
337
                $response['message']    = 'Terjadi kesalahan saat update data.';
338
                $response['status']     = true;
339
340
                return response()->json($response);
341
            }
342
        }
343
344
345
        $validator = Validator::make($request->all(), [
346
            'kegiatan_id'           => 'required',
347
            'tanggal_pendaftaran'   => 'required',
348
            'sekolah_id'            => 'required',
349
        ]);
350
351 View Code Duplication
        if ($validator->fails()) {
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...
352
            $error      = true;
353
            $message    = $validator->errors()->first();
354
355
        } else {
356
            $pendaftaran->kegiatan_id           = $request->input('kegiatan_id');
357
            $pendaftaran->tanggal_pendaftaran   = $request->input('tanggal_pendaftaran');
358
            $pendaftaran->sekolah_id            = $request->input('sekolah_id');
359
            $pendaftaran->save();
360
361
            $error      = false;
362
            $message    = 'Success';
363
        }
364
365
        $response['error']      = $error;
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...
366
        $response['message']    = $message;
367
        $response['status']     = true;
368
369
        return response()->json($response);
370
    }
371
372
    /**
373
     * Remove the specified resource from storage.
374
     *
375
     * @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...
376
     * @return \Illuminate\Http\Response
377
     */
378
    public function destroy($id)
379
    {
380
        if(!$this->checkRole(['superadministrator'])){
381
            $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...
382
            return json_encode($response);
383
        }
384
385
        $pendaftaran = $this->pendaftaran->findOrFail($id);
386
387
        if ($pendaftaran->delete()) {
388
            $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...
389
        } else {
390
            $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...
391
        }
392
393
        return json_encode($response);
394
    }
395
396
    protected function checkRole($role = array())
397
    {
398
        return Auth::user()->hasRole($role);
399
    }    
400
}
401