Passed
Push — bugfix/applicant-review-on-man... ( e4f444...3a8307 )
by Tristan
15:15 queued 10s
created

ApplicationPolicy::review()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 7
rs 10
c 0
b 0
f 0
cc 3
nc 3
nop 2
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\JobApplication;
7
use App\Policies\BasePolicy;
8
use Illuminate\Auth\Access\HandlesAuthorization;
9
10
class ApplicationPolicy extends BasePolicy
0 ignored issues
show
Coding Style introduced by
Missing doc comment for class ApplicationPolicy
Loading history...
11
{
12
    use HandlesAuthorization;
13
14
    /**
15
     * Determine whether the user can view the jobApplication.
16
     *
17
     * @param  \App\Models\User  $user
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 4 spaces after parameter type; 2 found
Loading history...
18
     * @param  \App\JobApplication  $jobApplication
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...
19
     * @return mixed
0 ignored issues
show
Coding Style introduced by
Tag cannot be grouped with parameter tags in a doc comment
Loading history...
20
     */
21
    public function view(User $user, JobApplication $jobApplication)
22
    {
23
        $authApplicant = ($user->user_role->name === "applicant" &&
24
            $user->applicant->id === $jobApplication->applicant_id);
25
        $authManager = ($user->hasRole('manager') &&
26
            $jobApplication->job_poster->manager->user->is($user));
27
28
        return $authApplicant||$authManager;
29
    }
30
31
    /**
32
     * Determine whether the user can create jobApplications.
33
     *
34
     * @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...
35
     * @return mixed
0 ignored issues
show
Coding Style introduced by
Tag cannot be grouped with parameter tags in a doc comment
Loading history...
36
     */
37
    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

37
    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...
38
    {
39
        return true;
40
    }
41
42
    /**
43
     * Determine whether the user can update the jobApplication.
44
     *
45
     * @param  \App\Models\User  $user
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 4 spaces after parameter type; 2 found
Loading history...
46
     * @param  \App\JobApplication  $jobApplication
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...
47
     * @return mixed
0 ignored issues
show
Coding Style introduced by
Tag cannot be grouped with parameter tags in a doc comment
Loading history...
48
     */
49
    public function update(User $user, JobApplication $jobApplication)
50
    {
51
        return $user->user_role->name === "applicant" &&
52
            $user->applicant->id === $jobApplication->applicant_id &&
53
            $jobApplication->application_status->name == "draft" &&
54
            $jobApplication->job_poster->isOpen();
55
    }
56
57
    /**
58
     * Determine whether the user can delete the jobApplication.
59
     *
60
     * @param  \App\Models\User  $user
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 4 spaces after parameter type; 2 found
Loading history...
61
     * @param  \App\JobApplication  $jobApplication
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...
62
     * @return mixed
0 ignored issues
show
Coding Style introduced by
Tag cannot be grouped with parameter tags in a doc comment
Loading history...
63
     */
64
    public function delete(User $user, JobApplication $jobApplication)
65
    {
66
        return $user->user_role->name === "applicant" &&
67
            $user->applicant->id === $jobApplication->applicant_id &&
68
            $jobApplication->application_status->name == "draft";
69
    }
70
71
    /**
72
     * Determine whether the user can review the jobApplication.
73
     *
74
     * @param  \App\Models\User  $user
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 4 spaces after parameter type; 2 found
Loading history...
75
     * @param  \App\JobApplication  $jobApplication
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...
76
     * @return mixed
0 ignored issues
show
Coding Style introduced by
Tag cannot be grouped with parameter tags in a doc comment
Loading history...
77
     */
78
    public function review(User $user, JobApplication $jobApplication)
79
    {
80
        //Only the manager in charge of the accompanying job can review an application,
81
        // and only if it has been submitted
82
        return $user->hasRole('manager') &&
83
            $jobApplication->job_poster->manager->user->id == $user->id &&
84
            $jobApplication->application_status->name != "draft";
85
    }
86
}
87