Completed
Push — api/develop ( 99bc8b...fe7067 )
by Bertrand
06:57
created

TerminationReasonRequest::authorize()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 24
Code Lines 13

Duplication

Lines 24
Ratio 100 %

Code Coverage

Tests 10
CRAP Score 5.0187

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 24
loc 24
ccs 10
cts 11
cp 0.9091
rs 8.5125
cc 5
eloc 13
nc 5
nop 0
crap 5.0187
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\PIM\Configuration;
11
12
use HRis\Http\Requests\Request;
13
14 View Code Duplication
class TerminationReasonRequest extends Request
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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:termination_reasons',
28 8
            ];
29
        }
30
31 10
        return [];
32
    }
33
34
    /**
35
     * Determine if the user is authorized to make this request.
36
     *
37
     * @return bool
38
     *
39
     * @author Bertrand Kintanar <[email protected]>
40
     */
41 14
    public function authorize()
42
    {
43 14
        $permission = 'pim.configuration.termination-reasons';
44
45
        // Create
46 14
        if ($this->isMethod('post')) {
47 8
            return $this->logged_user->hasAccess($permission.'.create');
48
        } // Delete
49
        else {
50 10
            if ($this->isMethod('delete')) {
51 4
                return $this->logged_user->hasAccess($permission.'.delete');
52
            } // View
53
            else {
54 6
                if ($this->isMethod('get')) {
55 2
                    return $this->logged_user->hasAccess($permission.'.view');
56
                } // Update
57
                else {
58 4
                    if ($this->isMethod('patch')) {
59 4
                        return $this->logged_user->hasAccess($permission.'.update');
60
                    }
61
                }
62
            }
63
        }
64
    }
65
}
66