Completed
Push — api/develop ( 20ea63...2875f0 )
by Bertrand
05:58
created

PayGradeRequest::rules()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 12
ccs 7
cts 7
cp 1
rs 9.4285
cc 2
eloc 7
nc 2
nop 0
crap 2
1
<?php
2
3
/**
4
 * This file is part of the HRis Software package.
5
 *
6
 * HRis - Human Resource and Payroll System
7
 *
8
 * @link    http://github.com/HB-Co/HRis
9
 */
10
namespace HRis\Api\Requests\Admin\Job;
11
12
use HRis\Http\Requests\Request;
13
14
class PayGradeRequest extends Request
15
{
16
    /**
17
     * Get the validation rules that apply to the request.
18
     *
19
     * @return array
20
     *
21
     * @author Bertrand Kintanar <[email protected]>
22
     */
23 14
    public function rules()
24
    {
25 14
        if ($this->isMethod('post')) {
26
            return [
27 8
                'name'       => 'required|unique:pay_grades',
28 8
                'min_salary' => 'required',
29 8
                'max_salary' => 'required',
30 8
            ];
31
        }
32
33 10
        return [];
34
    }
35
36
    /**
37
     * Determine if the user is authorized to make this request.
38
     *
39
     * @return bool
40
     *
41
     * @author Bertrand Kintanar <[email protected]>
42
     */
43 14
    public function authorize()
44
    {
45 14
        $permission = 'admin.job.pay-grades';
46
47
        // Create
48 14
        if ($this->isMethod('post')) {
49 8
            return $this->logged_user->hasAccess($permission.'.create');
50
        } // Delete
51
        else {
52 10
            if ($this->isMethod('delete')) {
53 4
                return $this->logged_user->hasAccess($permission.'.delete');
54
            } // View
55
            else {
56 6
                if ($this->isMethod('get')) {
57 2
                    return $this->logged_user->hasAccess($permission.'.view');
58
                } // Update
59
                else {
60 4
                    if ($this->isMethod('patch')) {
61 4
                        return $this->logged_user->hasAccess($permission.'.update');
62
                    }
63
                }
64
            }
65
        }
66
    }
67
}
68