Completed
Push — api/develop ( c699db...24e0a4 )
by Bertrand
14:51
created

ReportsToRequest::rules()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 18
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 18
ccs 11
cts 11
cp 1
rs 9.4285
cc 3
eloc 11
nc 2
nop 0
crap 3
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\Profile;
11
12
use HRis\Http\Requests\Request;
13
14
/**
15
 * Class ReportsToRequest.
16
 */
17
class ReportsToRequest extends Request
18
{
19
    /**
20
     * Get the validation rules that apply to the request.
21
     *
22
     * @return array
23
     *
24
     * @author Bertrand Kintanar <[email protected]>
25
     */
26 12
    public function rules()
27
    {
28 12
        if ($this->isMethod('post') || $this->isMethod('patch')) {
29
            return [
30
                'employee_id'   => [
31 10
                    'required',
32 10
                    'unique_with:employee_supervisors,supervisor_id',
33 10
                ],
34
                'supervisor_id' => [
35 10
                    'required',
36 10
                    'unique_with:employee_supervisors,employee_id',
37 10
                    'different:employee_id',
38 10
                ],
39 10
            ];
40
        }
41
42 4
        return [];
43
    }
44
45
    /**
46
     * Determine if the user is authorized to make this request.
47
     *
48
     * @return bool
49
     *
50
     * @author Bertrand Kintanar <[email protected]>
51
     */
52 12
    public function authorize()
53
    {
54 12
        $permission = $this->is('*pim/*') ? 'pim.reports-to' : 'profile.reports-to';
55
56 12
        return $this->hasAccess($permission);
57
    }
58
}
59
60