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

PayrollController::create()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
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 PayrollController extends Controller
9
{
10
    public function __construct()
11
    {
12
        $this->middleware('auth');
13
    }
14
15
    /**
16
     * Display a listing of the resource.
17
     *
18
     * @return \Illuminate\Http\Response
19
     */
20
    public function index()
21
    {
22
        $payrolls = \App\Models\OpenPayroll\Payroll::latest()->paginate();
23
24
        return view('payroll.index', compact('payrolls'));
0 ignored issues
show
Bug Best Practice introduced by
The expression return view('payroll.index', compact('payrolls')) returns the type Illuminate\View\View which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
25
    }
26
27
    /**
28
     * Show the form for creating a new resource.
29
     *
30
     * @return \Illuminate\Http\Response
31
     */
32
    public function create()
33
    {
34
        return view('payroll.create');
0 ignored issues
show
Bug Best Practice introduced by
The expression return view('payroll.create') returns the type Illuminate\View\View which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
35
    }
36
37
    /**
38
     * Store a newly created resource in storage.
39
     *
40
     * @param \Illuminate\Http\Request $request
41
     *
42
     * @return \Illuminate\Http\Response
43
     */
44
    public function store(Request $request)
45
    {
46
        $this->validate($request, [
47
            'month' => 'required|min:1|max:12',
48
            'year'  => 'required',
49
            'date'  => 'required',
50
        ]);
51
52
        $payroll = \App\Models\OpenPayroll\Payroll::create($request->only('user_id', 'month', 'year', 'date'));
53
54
        swal()->success('Payroll', 'You have successfully created a payroll.');
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

54
        /** @scrutinizer ignore-call */ 
55
        swal()->success('Payroll', 'You have successfully created a payroll.');
Loading history...
55
56
        return redirect()->route('payroll.show', $payroll->hashslug);
0 ignored issues
show
Bug Best Practice introduced by
The expression return redirect()->route...w', $payroll->hashslug) returns the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
Bug Best Practice introduced by
The property hashslug does not exist on App\Models\OpenPayroll\Payroll. Since you implemented __get, consider adding a @property annotation.
Loading history...
57
    }
58
59
    /**
60
     * Display the specified resource.
61
     *
62
     * @param int $id
63
     *
64
     * @return \Illuminate\Http\Response
65
     */
66
    public function show($id)
67
    {
68
        $payroll = \App\Models\OpenPayroll\Payroll::with('payslips', 'payslips.user')->findByHashslugOrId($id);
69
70
        return view('payroll.show', compact('payroll'));
0 ignored issues
show
Bug Best Practice introduced by
The expression return view('payroll.show', compact('payroll')) returns the type Illuminate\View\View which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
71
    }
72
73
    /**
74
     * Show the form for editing the specified resource.
75
     *
76
     * @param int $id
77
     *
78
     * @return \Illuminate\Http\Response
79
     */
80
    public function edit($id)
81
    {
82
    }
83
84
    /**
85
     * Update the specified resource in storage.
86
     *
87
     * @param \Illuminate\Http\Request $request
88
     * @param int                      $id
89
     *
90
     * @return \Illuminate\Http\Response
91
     */
92
    public function update(Request $request, $id)
93
    {
94
    }
95
96
    /**
97
     * Remove the specified resource from storage.
98
     *
99
     * @param int $id
100
     *
101
     * @return \Illuminate\Http\Response
102
     */
103
    public function destroy($id)
104
    {
105
        $payroll = \App\Models\OpenPayroll\Payroll::whereHashslug($id)->firstOrFail();
106
107
        if ($payroll->is_locked) {
0 ignored issues
show
Bug Best Practice introduced by
The property is_locked does not exist on App\Models\OpenPayroll\Payroll. Since you implemented __get, consider adding a @property annotation.
Loading history...
108
            swal()->error('Payroll', 'You cannot delete locked payroll.');
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()->error('Payroll', 'You cannot delete locked payroll.');
Loading history...
109
110
            return redirect()->route('payroll.index');
0 ignored issues
show
Bug Best Practice introduced by
The expression return redirect()->route('payroll.index') returns the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
111
        }
112
113
        $payroll->delete();
114
        swal()->success('Payroll', 'You have successfully delete a payroll');
115
116
        return redirect()->route('payroll.index');
0 ignored issues
show
Bug Best Practice introduced by
The expression return redirect()->route('payroll.index') returns the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
117
    }
118
}
119