Completed
Push — api/develop ( 3a7de4...11afe9 )
by Bertrand
04:51
created

EmploymentStatusRequest   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 50
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 93.33%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 7
c 1
b 0
f 1
lcom 1
cbo 1
dl 50
loc 50
ccs 14
cts 15
cp 0.9333
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A rules() 8 8 2
B authorize() 24 24 5

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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