Completed
Push — master ( ffc0ef...053644 )
by Nasrul Hazim
01:54
created

EarningController::edit()   A

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 EarningController 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\EarningType::all();
27
28
        return view('earnings.create', compact('types'));
0 ignored issues
show
Bug Best Practice introduced by
The expression return view('earnings.create', 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\EarningType::find($request->type);
48
49
        $payslip->earnings()->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
            'earning_type_id' => $request->type,
53
            'name'            => $type->name,
0 ignored issues
show
Bug Best Practice introduced by
The property name does not exist on App\Models\OpenPayroll\EarningType. Since you implemented __get, consider adding a @property annotation.
Loading history...
54
            'description'     => $type->name,
55
            'amount'          => money()->toMachine($request->amount),
56
        ]);
57
58
        swal()->success('Earning', '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

58
        /** @scrutinizer ignore-call */ 
59
        swal()->success('Earning', 'You have successfully added new earning.');
Loading history...
59
60
        return redirect()->route('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...
61
    }
62
63
    /**
64
     * Display the specified resource.
65
     *
66
     * @param int $id
67
     *
68
     * @return \Illuminate\Http\Response
69
     */
70
    public function show($id)
71
    {
72
    }
73
74
    /**
75
     * Show the form for editing the specified resource.
76
     *
77
     * @param int $id
78
     *
79
     * @return \Illuminate\Http\Response
80
     */
81
    public function edit($id)
82
    {
83
    }
84
85
    /**
86
     * Update the specified resource in storage.
87
     *
88
     * @param \Illuminate\Http\Request $request
89
     * @param int                      $id
90
     *
91
     * @return \Illuminate\Http\Response
92
     */
93
    public function update(Request $request, $id)
94
    {
95
    }
96
97
    /**
98
     * Remove the specified resource from storage.
99
     *
100
     * @param int $id
101
     *
102
     * @return \Illuminate\Http\Response
103
     */
104
    public function destroy($id)
105
    {
106
        \App\Models\OpenPayroll\Earning::hashslug($id)->delete();
107
108
        swal()->success('Earning', '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

108
        /** @scrutinizer ignore-call */ 
109
        swal()->success('Earning', 'You have successfully delete an earning.');
Loading history...
109
110
        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...
111
    }
112
}
113