Passed
Push — task/comments-api ( 6d7a22...c7d753 )
by Yonathan
22:36 queued 15:14
created

JobPolicy::storeComment()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
namespace App\Policies;
4
5
use App\Models\User;
6
use App\Models\JobPoster;
7
use App\Policies\BasePolicy;
8
use Illuminate\Support\Facades\Log;
9
10
class JobPolicy extends BasePolicy
11
{
12
13
    /**
14
     * Determine whether the user can view the job poster.
15
     *
16
     * @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...
17
     * @param  \App\Models\JobPoster  $jobPoster
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...
18
     * @return mixed
19
     */
20
    public function view(?User $user, JobPoster $jobPoster)
0 ignored issues
show
Coding Style introduced by
Expected type hint "\App\Models\User"; found "?User" for $user
Loading history...
21
    {
22
        // Anyone can view a published job
23
        // Only the manager that created it can view an unpublished job
24
        return $jobPoster->status() == 'published' || $jobPoster->status() == 'closed' ||
25
        (
26
            $user &&
27
            $user->isManager() &&
28
            $jobPoster->manager->user_id == $user->id
29
        );
30
    }
31
32
    /**
33
     * Determine whether the user can create job posters.
34
     *
35
     * @param  \App\Models\User $user User to test against.
36
     * @return mixed
37
     */
38
    public function create(User $user)
39
    {
40
        // Any manager can create a new job poster.
41
        return $user->isManager();
42
    }
43
44
    /**
45
     * Determine whether the user can update the job poster.
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 6 spaces after parameter type; 2 found
Loading history...
48
     * @param  \App\Models\JobPoster  $jobPoster
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...
49
     * @return mixed
50
     */
51
    public function update(User $user, JobPoster $jobPoster)
52
    {
53
        // Only managers can edit jobs, and only their own, managers can't publish jobs or edit published jobs
54
        return $user->isManager() &&
55
        $jobPoster->manager->user->id == $user->id &&
56
        !$jobPoster->published;
57
    }
58
59
    /**
60
     * Determine whether the user can delete the job poster.
61
     *
62
     * @param \App\Models\User      $user      User object making the request.
63
     * @param \App\Models\JobPoster $jobPoster Job Poster object being acted upon.
64
     *
65
     * @return boolean
66
     */
67
    public function delete(User $user, JobPoster $jobPoster) : bool
68
    {
69
        // Jobs can only be deleted when they're in the 'draft'
70
        // state, and only by managers that created them.
71
        return $user->isManager() &&
72
        $jobPoster->manager->user->id == $user->id &&
73
        !$jobPoster->published;
74
    }
75
76
    /**
77
     * Determine whether the user can submit a job poster for review.
78
     *
79
     * @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...
80
     * @param  \App\Models\JobPoster  $jobPoster
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...
81
     * @return mixed
82
     */
83
    public function submitForReview(User $user, JobPoster $jobPoster)
84
    {
85
        // Only upgradedManagers can submit jobs for review, only their own jobs, and only if they're still drafts.
86
        // NOTE: this is one of the only permissions to require an upgradedManager, as opposed to a demoManager.var
87
        return $user->isUpgradedManager() &&
88
            $jobPoster->manager->user->id == $user->id &&
89
            $jobPoster->status() === 'draft';
90
    }
91
    /**
92
     * Determine whether the user can review applications to the job poster.
93
     *
94
     * @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...
95
     * @param  \App\Models\JobPoster  $jobPoster
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...
96
     * @return mixed
97
     */
98
    public function reviewApplicationsFor(User $user, JobPoster $jobPoster)
99
    {
100
        // Only managers can review applications, and only for their own jobs.
101
        return $user->isManager() &&
102
            $jobPoster->manager->user->id == $user->id &&
103
            $jobPoster->isClosed();
104
    }
105
106
     /**
107
     * Determine whether the user can view the comments.
108
     *
109
     * @param \App\Models\User $user
2 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 4 spaces after parameter type; 1 found
Loading history...
110
     * @param \App\Models\Comment $comment
2 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Superfluous parameter comment
Loading history...
111
     * @return bool
1 ignored issue
show
Coding Style introduced by
Expected "boolean" but found "bool" for function return type
Loading history...
112
     */
113
    public function viewComments(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

113
    public function viewComments(/** @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...
114
    {
115
        // Only the manager that created a comment can view the comment.
116
        // Only Hr advisors who have claimed a job can view the comments.
117
        return true;
118
    }
119
120
    /**
121
     * Determine whether the user can create a comment
122
     *
123
     * @param \App\Models\User $user User to test against
1 ignored issue
show
Coding Style Documentation introduced by
Parameter comment must end with a full stop
Loading history...
124
     * @return bool
1 ignored issue
show
Coding Style introduced by
Expected "boolean" but found "bool" for function return type
Loading history...
125
     */
126
    public function storeComment(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

126
    public function storeComment(/** @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...
127
    {
128
        // Any manager or HR adviser can create a new comment.
129
        return true;
130
    }
131
}
132