Completed
Push — master ( 62a982...c89019 )
by
unknown
9s
created

TarifController::destroy()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
nc 1
nop 2
dl 0
loc 6
rs 9.4285
c 1
b 0
f 0
1
<?php 
2
3
namespace Bantenprov\PemakaianBahuJalan\Http\Controllers;
4
5
use App\Http\Controllers\Controller;
6
use Illuminate\Http\Request;
7
use Bantenprov\PemakaianBahuJalan\Facades\Tarif;
8
use Bantenprov\PemakaianBahuJalan\Models\TarifModel;
9
use Bantenprov\MasterTarif\Models\MasterTarifModel;
10
use Ramsey\Uuid\Uuid;
11
12
class TarifController extends Controller 
13
{
14
  /**
15
   * Display a listing of the resource.
16
   *
17
   * @return Response
18
   */
19
  public function index()
20
  {
21
    $tarifs = TarifModel::all();
22
    return view('pemakaian-bahu-jalan::index',compact('tarifs'));
23
  }
24
25
  /**
26
   * Show the form for creating a new resource.
27
   *
28
   * @return Response
29
   */
30
  public function create()
31
  {
32
    //$mastertarifs = MasterTarifModel::where('levelunker', '=', 1)->get();
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...
33
    $mastertarifs = MasterTarifModel::all();
34
    return view('pemakaian-bahu-jalan::create',compact('mastertarifs')); 
35
  }
36
37
  /**
38
   * Store a newly created resource in storage.
39
   *
40
   * @return Response
41
   */
42 View Code Duplication
  public function store(Request $request)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
43
  {
44
    
45
    //$daftar_retribusi = TarifModel::find($request->daftar_retribusi_id);
0 ignored issues
show
Unused Code Comprehensibility introduced by
54% 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...
46
    $request->validate([            
47
        'uraian'                => 'required',
48
        'wilayah_kota'          => 'required',
49
        'wilayah_kabupaten'     => 'required',
50
        'satuan'                => 'required',
51
        'master_tarif_id'       => 'required',        
52
    ]);
53
54
    /*
0 ignored issues
show
Unused Code Comprehensibility introduced by
71% 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...
55
    if(is_null($daftar_retribusi)){
56
        return redirect()->back()->withErrors('Error : retribusi yang dipilih tidak ditemukan');
57
    }
58
    */
59
60
    // if($request->status > 1 && $request->status < 0){
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% 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...
61
    //     return redirect()->back()->withErrors('Error : status salah');
0 ignored issues
show
Unused Code Comprehensibility introduced by
69% 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...
62
    // }
63
    if($request->tarif == 'on'){
64
      $tarif  = 0;
65
    }else{
66
      $tarif  = 1;
67
    }
68
69
    TarifModel::create([
70
        'uuid'                  => Uuid::uuid5(Uuid::NAMESPACE_DNS, 'bantenprov.go.id'.date('YmdHis')),
71
        'uraian'                => $request->uraian,
72
        'tarif'                 => $tarif,
73
        'wilayah_kota'          => $request->wilayah_kota,
74
        'wilayah_kabupaten'     => $request->wilayah_kabupaten,
75
        'satuan'                => $request->satuan,
76
        'master_tarif_id'       => $request->master_tarif_id,
77
        'user_id'               => \Auth::user()->id,
78
        'user_update'           => \Auth::user()->id,
79
    ]);
80
    $request->session()->flash('message', 'Successfully add new data');
81
    return redirect()->route('tarif.index');
82
  }
83
84
  /**
85
   * Display the specified resource.
86
   *
87
   * @param  int  $id
88
   * @return Response
89
   */
90
  public function show($id)
91
  {
92
    
93
  }
94
95
  /**
96
   * Show the form for editing the specified resource.
97
   *
98
   * @param  int  $id
99
   * @return Response
100
   */
101
  public function edit($id)
102
  {
103
    $tarif = TarifModel::find($id);
104
    $mastertarifs = MasterTarifModel::all();    
105
    return view('pemakaian-bahu-jalan::edit', compact('tarif','mastertarifs'));
106
  }
107
108
  /**
109
   * Update the specified resource in storage.
110
   *
111
   * @param  int  $id
112
   * @return Response
113
   */
114 View Code Duplication
  public function update(Request $request, $id)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
115
  {
116
    $request->validate([            
117
      'uraian'                => 'required',
118
      'wilayah_kota'          => 'required',
119
      'wilayah_kabupaten'     => 'required',
120
      'satuan'                => 'required',
121
      'master_tarif_id'       => 'required',        
122
    ]);
123
  
124
    if($request->tarif == 'on'){
125
      $tarif  = 1;
126
    }else{
127
      $tarif  = 0;
128
    }
129
    TarifModel::find($id)->update([            
130
        'uuid'                  => Uuid::uuid5(Uuid::NAMESPACE_DNS, 'bantenprov.go.id'.date('YmdHis')),
131
        'uraian'                => $request->uraian,
132
        'tarif'                 => $tarif,
133
        'wilayah_kota'          => $request->wilayah_kota,
134
        'wilayah_kabupaten'     => $request->wilayah_kabupaten,
135
        'satuan'                => $request->satuan,
136
        'master_tarif_id'       => $request->master_tarif_id,
137
        'user_id'               => \Auth::user()->id,
138
        'user_update'           => \Auth::user()->id,
139
    ]);
140
    $request->session()->flash('message', 'Successfully add new data');
141
    return redirect()->route('tarif.index');
142
  }
143
144
  /**
145
   * Remove the specified resource from storage.
146
   *
147
   * @param  int  $id
148
   * @return Response
149
   */
150
  public function destroy(Request $request, $id)
151
  {
152
    TarifModel::find($id)->delete();
153
    $request->session()->flash('message', 'Successfully delete data');
154
    return redirect()->route('tarif.index');
155
  }
156
  
157
}
158
159
?>
0 ignored issues
show
Best Practice introduced by
It is not recommended to use PHP's closing tag ?> in files other than templates.

Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.

A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.

Loading history...