Passed
Push — feature/screening-plan-l10n ( 75403d...7eec86 )
by Tristan
06:23 queued 55s
created

ApplicantPolicy   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 90
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

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

7 Methods

Rating   Name   Duplication   Size   Complexity  
A view() 0 6 4
A restore() 0 2 1
A delete() 0 2 1
A forceDelete() 0 2 1
A update() 0 4 2
A create() 0 3 1
A managerCanViewApplicant() 0 7 1
1
<?php
2
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
12
{
13
14
    /**
15
     * Returns true if $manager owns a job to which $applicant has applied
16
     * @param  Manager   $manager   [description]
2 ignored issues
show
Coding Style introduced by
Parameter comment must start with a capital letter
Loading history...
Coding Style Documentation introduced by
Parameter comment must end with a full stop
Loading history...
17
     * @param  Applicant $applicant [description]
2 ignored issues
show
Coding Style introduced by
Parameter comment must start with a capital letter
Loading history...
Coding Style Documentation introduced by
Parameter comment must end with a full stop
Loading history...
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...
19
     */
20
    protected function managerCanViewApplicant(Manager $manager, Applicant $applicant) {
0 ignored issues
show
introduced by
Method \App\Policies\ApplicantPolicy::managerCanViewApplicant() does not have return type hint for its return value but it should be possible to add it based on @return annotation "[type]".
Loading history...
21
        $applicant_id = $applicant->id;
22
        return JobPoster::where('manager_id', $manager->id)
23
            ->whereHas('submitted_applications', function ($q) use ($applicant_id){
0 ignored issues
show
introduced by
Closure does not have void return type hint.
Loading history...
Coding Style introduced by
Expected 1 space before opening brace; found 0
Loading history...
24
                $q->where('applicant_id', $applicant_id);
25
            })
26
            ->get()->isNotEmpty();
27
    }
28
29
    /**
30
     * Determine whether the user can view the applicant.
31
     *
32
     * @param  \App\Models\User  $user
2 ignored issues
show
Coding Style Documentation 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
2 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter type; 2 found
Loading history...
34
     * @return mixed
35
     */
36
    public function view(User $user, Applicant $applicant)
37
    {
38
        $authApplicant =  $user->hasRole('applicant') &&
39
            $applicant->user->is($user);
40
        $authManager = $user->hasRole('manager') && $this->managerCanViewApplicant($user->manager, $applicant);
41
        return $authApplicant || $authManager;
42
    }
43
44
    /**
45
     * Determine whether the user can create applicants.
46
     *
47
     * @param  \App\Models\User  $user
2 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter type; 2 found
Loading history...
48
     * @return mixed
49
     */
50
    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
        return false;
53
    }
54
55
    /**
56
     * Determine whether the user can update the applicant.
57
     *
58
     * @param  \App\Models\User  $user
2 ignored issues
show
Coding Style Documentation 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
2 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter type; 2 found
Loading history...
60
     * @return mixed
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
2 ignored issues
show
Coding Style Documentation 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
2 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter type; 2 found
Loading history...
73
     * @return mixed
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
2 ignored issues
show
Coding Style Documentation 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
2 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter type; 2 found
Loading history...
85
     * @return mixed
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
2 ignored issues
show
Coding Style Documentation 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
2 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter type; 2 found
Loading history...
97
     * @return mixed
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