Completed
Push — master ( 72282c...462347 )
by
unknown
9s
created

TarifController::update()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 27
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 19
nc 1
nop 2
dl 0
loc 27
rs 8.8571
c 1
b 0
f 0
1
<?php namespace Bantenprov\PelayananKesehatan\Http\Controllers;
2
3
use App\Http\Controllers\Controller;
4
use Illuminate\Http\Request;
5
6
/* Model */
7
use Bantenprov\PelayananKesehatan\Facades\PelayananKesehatan;
8
use Bantenprov\PelayananKesehatan\Models\TarifModel;
9
use Bantenprov\MasterTarif\Models\MasterTarifModel;
10
11
/* ETC */
12
use Ramsey\Uuid\Uuid;
13
14
/**
15
 * The TarifController class.
16
 *
17
 * @package Bantenprov\PelayananKesehatan
18
 * @author  bantenprov <[email protected]>
19
 */
20
class TarifController extends Controller
21
{
22
23
    public function index()
24
    {
25
26
        $tarifs = TarifModel::with('getMasterTarif')->get();
27
28
        return view('pelayanan-kesehatan::tarif.index',compact('tarifs'));
29
    }
30
31
    public function create()
32
    {
33
        $master_tarifs = MasterTarifModel::all();
34
35
        return view('pelayanan-kesehatan::tarif.create', compact('master_tarifs'));
36
    }
37
38
    public function store(Request $request)
39
    {
40
        $master_tarif = MasterTarifModel::find($request->master_tarif);
0 ignored issues
show
Unused Code introduced by
$master_tarif 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...
41
42
        $request->validate([
43
            'uraian'            => 'required',
44
            'tarif'             => 'required',
45
            'jasa_pelayanan'    => 'required',
46
            'jasa_sarana'       => 'required',
47
            'satuan'            => 'required',
48
            'master_tarif_id'   => 'required',
49
        ]);
50
51
        TarifModel::create([
52
            'uuid'              => Uuid::uuid5(Uuid::NAMESPACE_DNS, 'bantenprov.go.id'.date('YmdHis')),
53
            'uraian'            => $request->uraian,
54
            'tarif'             => $request->tarif,
55
            'jasa_pelayanan'    => $request->jasa_pelayanan,
56
            'jasa_sarana'       => $request->jasa_sarana,
57
            'satuan'            => $request->satuan,
58
            'master_tarif_id'   => $request->master_tarif_id,
59
            'user_id'           => \Auth::user()->id,
60
            'user_update'       => \Auth::user()->id,
61
        ]);
62
63
        $request->session()->flash('message', 'Success add new tarif.');
64
65
        return redirect()->route('tarif.index');
66
    }
67
68
    public function show($id)
69
    {
70
        $tarif = TarifModel::find($id);
71
72
        return view('pelayanan-kesehatan::tarif.show', compact('tarif'));
73
    }
74
75
    public function edit($id)
76
    {
77
        $tarif = TarifModel::find($id);
78
        $master_tarifs = MasterTarifModel::all();
79
80
        return view('pelayanan-kesehatan::tarif.edit', compact('tarif','master_tarifs'));
81
    }
82
83
    public function update(Request $request, $id)
84
    {
85
        $master_tarif = MasterTarifModel::find($request->master_tarif);
0 ignored issues
show
Unused Code introduced by
$master_tarif 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...
86
87
        $request->validate([
88
            'uraian'            => 'required',
89
            'tarif'             => 'required|unique:tarifs,id,'.$id,
90
            'jasa_pelayanan'    => 'required',
91
            'jasa_sarana'       => 'required',
92
            'satuan'            => 'required',
93
            'master_tarif_id'   => 'required',
94
        ]);
95
96
        TarifModel::find($id)->update([
97
            'uraian'            => $request->uraian,
98
            'tarif'             => $request->tarif,
99
            'jasa_pelayanan'    => $request->jasa_pelayanan,
100
            'jasa_sarana'       => $request->jasa_sarana,
101
            'satuan'            => $request->satuan,
102
            'master_tarif_id'   => $request->master_tarif_id,
103
            'user_update'       => \Auth::user()->id,
104
        ]);
105
106
        $request->session()->flash('message', 'Success update tarif.');
107
108
        return redirect()->route('tarif.index');
109
    }
110
111
    public function destroy($id)
112
    {
113
        TarifModel::find($id)->delete();
114
115
        $request->session()->flash('message', 'Success delete tarif.');
0 ignored issues
show
Bug introduced by
The variable $request does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
116
117
        return redirect()->route('tarif.index');
118
    }
119
}
120