ReportsToRequest::rules()   A
last analyzed

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 0
Metric Value
dl 0
loc 18
ccs 11
cts 11
cp 1
rs 9.4285
c 0
b 0
f 0
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
 * NOTICE OF LICENSE
7
 *
8
 * Licensed under the 3-clause BSD License.
9
 *
10
 * This source file is subject to the 3-clause BSD License that is
11
 * bundled with this package in the LICENSE file.
12
 *
13
 * @version    alpha
14
 *
15
 * @author     Bertrand Kintanar <[email protected]>
16
 * @license    BSD License (3-clause)
17
 * @copyright  (c) 2014-2016, b8 Studios, Ltd
18
 *
19
 * @link       http://github.com/HB-Co/HRis
20
 */
21
22
namespace HRis\Api\Requests\Profile;
23
24
use Irradiate\Api\Requests\Request;
25
26
/**
27
 * Class ReportsToRequest.
28
 */
29
class ReportsToRequest extends Request
30
{
31
    /**
32
     * Get the validation rules that apply to the request.
33
     *
34
     * @return array
35
     *
36
     * @author Bertrand Kintanar <[email protected]>
37
     */
38 10
    public function rules()
39
    {
40 10
        if ($this->isMethod('post') || $this->isMethod('patch')) {
41
            return [
42
                'employee_id'   => [
43 10
                    'required',
44 10
                    'unique_with:employee_supervisors,supervisor_id',
45 10
                ],
46
                'supervisor_id' => [
47 10
                    'required',
48 10
                    'unique_with:employee_supervisors,employee_id',
49 10
                    'different:employee_id',
50 10
                ],
51 10
            ];
52
        }
53
54 2
        return [];
55
    }
56
57
    /**
58
     * Determine if the user is authorized to make this request.
59
     *
60
     * @return bool
61
     *
62
     * @author Bertrand Kintanar <[email protected]>
63
     */
64 10
    public function authorize()
65
    {
66 10
        $permission = $this->is('*pim/*') ? 'pim.reports-to' : 'profile.reports-to';
67
68 10
        return $this->hasAccess($permission);
69
    }
70
}
71