Completed
Push — dev ( 39ba5f...0b8cdb )
by Tristan
04:57 queued 04:51
created

ApplicantPolicy   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 90
Duplicated Lines 0 %

Test Coverage

Coverage 61.9%

Importance

Changes 0
Metric Value
wmc 11
eloc 13
dl 0
loc 90
ccs 13
cts 21
cp 0.619
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A restore() 0 2 1
A delete() 0 2 1
A forceDelete() 0 2 1
A update() 0 4 2
A view() 0 6 4
A create() 0 3 1
A managerCanViewApplicant() 0 7 1
1
<?php
2
0 ignored issues
show
Coding Style introduced by
Missing file doc comment
Loading history...
3
namespace App\Policies;
4
5
use App\Models\User;
6
use App\Models\Manager;
7
use App\Models\Applicant;
8
use App\Models\JobPoster;
9
use App\Policies\BasePolicy;
10
11
class ApplicantPolicy extends BasePolicy
0 ignored issues
show
Coding Style introduced by
Missing doc comment for class ApplicantPolicy
Loading history...
12
{
13
14
    /**
15
     * Returns true if $manager owns a job to which $applicant has applied
16
     * @param  Manager   $manager   [description]
0 ignored issues
show
Coding Style introduced by
There must be exactly one blank line before the tags in a doc comment
Loading history...
17
     * @param  Applicant $applicant [description]
18
     * @return [type]               [description]
0 ignored issues
show
Documentation Bug introduced by
The doc comment [type] at position 0 could not be parsed: Unknown type name '[' at position 0 in [type].
Loading history...
Coding Style introduced by
Tag cannot be grouped with parameter tags in a doc comment
Loading history...
19
     */
20 2
    protected function managerCanViewApplicant(Manager $manager, Applicant $applicant) {
21 2
        $applicant_id = $applicant->id;
22 2
        return JobPoster::where('manager_id', $manager->id)
23
            ->whereHas('submitted_applications', function ($q) use ($applicant_id){
0 ignored issues
show
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
Coding Style introduced by
Expected 1 space before opening brace; found 0
Loading history...
24 2
                $q->where('applicant_id', $applicant_id);
25 2
            })
0 ignored issues
show
Coding Style introduced by
For multi-line function calls, the closing parenthesis should be on a new line.

If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
); // Closing parenthesis on a new line.
Loading history...
26 2
            ->get()->isNotEmpty();
27
    }
28
29
    /**
30
     * Determine whether the user can view the applicant.
31
     *
32
     * @param  \App\Models\User  $user
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 6 spaces after parameter type; 2 found
Loading history...
33
     * @param  \App\Models\Applicant  $applicant
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter type; 2 found
Loading history...
34
     * @return mixed
0 ignored issues
show
Coding Style introduced by
Tag cannot be grouped with parameter tags in a doc comment
Loading history...
35
     */
36 2
    public function view(User $user, Applicant $applicant)
37
    {
38 2
        $authApplicant =  $user->hasRole('applicant') &&
39 2
            $applicant->user->is($user);
40 2
        $authManager = $user->hasRole('manager') && $this->managerCanViewApplicant($user->manager, $applicant);
41 2
        return $authApplicant || $authManager;
42
    }
43
44
    /**
45
     * Determine whether the user can create applicants.
46
     *
47
     * @param  \App\Models\User  $user
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter type; 2 found
Loading history...
48
     * @return mixed
0 ignored issues
show
Coding Style introduced by
Tag cannot be grouped with parameter tags in a doc comment
Loading history...
49
     */
50 2
    public function create(User $user)
0 ignored issues
show
Unused Code introduced by
The parameter $user is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

50
    public function create(/** @scrutinizer ignore-unused */ User $user)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
51
    {
52 2
        return false;
53
    }
54
55
    /**
56
     * Determine whether the user can update the applicant.
57
     *
58
     * @param  \App\Models\User  $user
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 6 spaces after parameter type; 2 found
Loading history...
59
     * @param  \App\Models\Applicant  $applicant
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter type; 2 found
Loading history...
60
     * @return mixed
0 ignored issues
show
Coding Style introduced by
Tag cannot be grouped with parameter tags in a doc comment
Loading history...
61
     */
62
    public function update(User $user, Applicant $applicant)
63
    {
64
        return $user->user_role->name === "applicant" &&
65
            $applicant->user_id === $user->id;
66
    }
67
68
    /**
69
     * Determine whether the user can delete the applicant.
70
     *
71
     * @param  \App\Models\User  $user
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 6 spaces after parameter type; 2 found
Loading history...
72
     * @param  \App\Models\Applicant  $applicant
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter type; 2 found
Loading history...
73
     * @return mixed
0 ignored issues
show
Coding Style introduced by
Tag cannot be grouped with parameter tags in a doc comment
Loading history...
74
     */
75
    public function delete(User $user, Applicant $applicant)
0 ignored issues
show
Unused Code introduced by
The parameter $applicant is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

75
    public function delete(User $user, /** @scrutinizer ignore-unused */ Applicant $applicant)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $user is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

75
    public function delete(/** @scrutinizer ignore-unused */ User $user, Applicant $applicant)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
76
    {
77
        //
78
    }
79
80
    /**
81
     * Determine whether the user can restore the applicant.
82
     *
83
     * @param  \App\Models\User  $user
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 6 spaces after parameter type; 2 found
Loading history...
84
     * @param  \App\Models\Applicant  $applicant
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter type; 2 found
Loading history...
85
     * @return mixed
0 ignored issues
show
Coding Style introduced by
Tag cannot be grouped with parameter tags in a doc comment
Loading history...
86
     */
87
    public function restore(User $user, Applicant $applicant)
0 ignored issues
show
Unused Code introduced by
The parameter $user is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

87
    public function restore(/** @scrutinizer ignore-unused */ User $user, Applicant $applicant)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $applicant is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

87
    public function restore(User $user, /** @scrutinizer ignore-unused */ Applicant $applicant)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
88
    {
89
        //
90
    }
91
92
    /**
93
     * Determine whether the user can permanently delete the applicant.
94
     *
95
     * @param  \App\Models\User  $user
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 6 spaces after parameter type; 2 found
Loading history...
96
     * @param  \App\Models\Applicant  $applicant
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter type; 2 found
Loading history...
97
     * @return mixed
0 ignored issues
show
Coding Style introduced by
Tag cannot be grouped with parameter tags in a doc comment
Loading history...
98
     */
99
    public function forceDelete(User $user, Applicant $applicant)
0 ignored issues
show
Unused Code introduced by
The parameter $user is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

99
    public function forceDelete(/** @scrutinizer ignore-unused */ User $user, Applicant $applicant)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $applicant is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

99
    public function forceDelete(User $user, /** @scrutinizer ignore-unused */ Applicant $applicant)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
100
    {
101
        //
102
    }
103
}
104