DeductionController::edit()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 0
nc 1
nop 1
dl 0
loc 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace App\Http\Controllers\OpenPayroll;
4
5
use App\Http\Controllers\Controller;
0 ignored issues
show
Bug introduced by
The type App\Http\Controllers\Controller was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use Illuminate\Http\Request;
7
8
class DeductionController extends Controller
9
{
10
    /**
11
     * Display a listing of the resource.
12
     *
13
     * @return \Illuminate\Http\Response
14
     */
15
    public function index()
16
    {
17
    }
18
19
    /**
20
     * Show the form for creating a new resource.
21
     *
22
     * @return \Illuminate\Http\Response
23
     */
24
    public function create()
25
    {
26
        $types = \App\Models\OpenPayroll\DeductionType::all();
27
28
        return view('open-payroll.deductions.create', compact('types'));
0 ignored issues
show
Bug Best Practice introduced by
The expression return view('open-payrol...ate', compact('types')) returns the type Illuminate\View\View which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
29
    }
30
31
    /**
32
     * Store a newly created resource in storage.
33
     *
34
     * @param \Illuminate\Http\Request $request
35
     *
36
     * @return \Illuminate\Http\Response
37
     */
38
    public function store(Request $request)
39
    {
40
        $this->validate($request, [
41
            'payslip' => 'required',
42
            'type'    => 'required',
43
            'amount'  => 'required',
44
        ]);
45
46
        $payslip = \App\Models\OpenPayroll\Payslip::with('payroll', 'user')->findByHashSlugOrId($request->payslip);
47
        $type    = \App\Models\OpenPayroll\DeductionType::find($request->type);
48
49
        \App\Models\OpenPayroll\Deduction::create([
50
            'user_id'           => $payslip->user_id,
0 ignored issues
show
Bug introduced by
The property user_id does not seem to exist on Illuminate\Database\Eloquent\Builder.
Loading history...
51
            'payroll_id'        => $payslip->payroll_id,
0 ignored issues
show
Bug introduced by
The property payroll_id does not seem to exist on Illuminate\Database\Eloquent\Builder.
Loading history...
52
            'payslip_id'        => $payslip->id,
0 ignored issues
show
Bug introduced by
The property id does not seem to exist on Illuminate\Database\Eloquent\Builder.
Loading history...
53
            'deduction_type_id' => $request->type,
54
            'name'              => $type->name,
0 ignored issues
show
Bug Best Practice introduced by
The property name does not exist on App\Models\OpenPayroll\DeductionType. Since you implemented __get, consider adding a @property annotation.
Loading history...
55
            'description'       => $request->description ?? $type->name,
56
            'amount'            => money()->toMachine($request->amount),
57
        ]);
58
59
        swal()->success('Deduction', 'You have successfully added new earning.');
0 ignored issues
show
Bug introduced by
The function swal was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

59
        /** @scrutinizer ignore-call */ 
60
        swal()->success('Deduction', 'You have successfully added new earning.');
Loading history...
60
61
        return redirect()->route('open-payroll.payslip.show', $request->payslip);
0 ignored issues
show
Bug Best Practice introduced by
The expression return redirect()->route...ow', $request->payslip) returns the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
62
    }
63
64
    /**
65
     * Display the specified resource.
66
     *
67
     * @param int $id
68
     *
69
     * @return \Illuminate\Http\Response
70
     */
71
    public function show($id)
72
    {
73
    }
74
75
    /**
76
     * Show the form for editing the specified resource.
77
     *
78
     * @param int $id
79
     *
80
     * @return \Illuminate\Http\Response
81
     */
82
    public function edit($id)
83
    {
84
    }
85
86
    /**
87
     * Update the specified resource in storage.
88
     *
89
     * @param \Illuminate\Http\Request $request
90
     * @param int                      $id
91
     *
92
     * @return \Illuminate\Http\Response
93
     */
94
    public function update(Request $request, $id)
95
    {
96
    }
97
98
    /**
99
     * Remove the specified resource from storage.
100
     *
101
     * @param int $id
102
     *
103
     * @return \Illuminate\Http\Response
104
     */
105
    public function destroy($id)
106
    {
107
        \App\Models\OpenPayroll\Deduction::hashslug($id)->delete();
108
109
        swal()->success('Deduction', 'You have successfully delete an earning.');
0 ignored issues
show
Bug introduced by
The function swal was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

109
        /** @scrutinizer ignore-call */ 
110
        swal()->success('Deduction', 'You have successfully delete an earning.');
Loading history...
110
111
        return back();
0 ignored issues
show
Bug Best Practice introduced by
The expression return back() returns the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
112
    }
113
}
114