Passed
Push — master ( 2c3721...94fb22 )
by Grant
09:10 queued 10s
created

JobPolicy   A

Complexity

Total Complexity 15

Size/Duplication

Total Lines 102
Duplicated Lines 0 %

Test Coverage

Coverage 47.62%

Importance

Changes 0
Metric Value
wmc 15
eloc 14
dl 0
loc 102
ccs 10
cts 21
cp 0.4762
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A view() 0 8 3
A create() 0 4 1
A update() 0 6 3
A review() 0 6 3
A restore() 0 2 1
A delete() 0 7 3
A forceDelete() 0 2 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
9
class JobPolicy extends BasePolicy
10
{
11
12
    /**
13
     * Determine whether the user can view the job poster.
14
     *
15
     * @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...
16
     * @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...
17
     * @return mixed
18
     */
19 8
    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...
20
    {
21
        //Anyone can view a published job
22
        //Only the manager that created it can view an unpublished job
23 8
        return $jobPoster->published ||
24
            (
25 4
                $user &&
26 8
                $jobPoster->manager->user->id == $user->id
27
            );
28
    }
29
30
    /**
31
     * Determine whether the user can create job posters.
32
     *
33
     * @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...
34
     * @return mixed
35
     */
36 3
    public function create(User $user)
37
    {
38
        //Any manager can create a new job poster
39 3
        return $user->user_role->name == 'manager';
40
    }
41
42
    /**
43
     * Determine whether the user can update the job poster.
44
     *
45
     * @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...
46
     * @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...
47
     * @return mixed
48
     */
49 7
    public function update(User $user, JobPoster $jobPoster)
50
    {
51
        //Only managers can edit jobs, and only their own, managers can't publish jobs or edit published jobs
52 7
        return $user->user_role->name == 'manager' &&
53 7
            $jobPoster->manager->user->id == $user->id &&
54 7
            !$jobPoster->published;
55
    }
56
57
    /**
58
     * Determine whether the user can review applications to the job poster.
59
     *
60
     * @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...
61
     * @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...
62
     * @return mixed
63
     */
64
    public function review(User $user, JobPoster $jobPoster)
65
    {
66
        //Only managers can edit jobs, and only their own, managers can't publish jobs or edit published jobs
67
        return $user->user_role->name == 'manager' &&
68
            $jobPoster->manager->user->id == $user->id &&
69
            $jobPoster->isClosed();
70
    }
71
72
73
    /**
74
     * Determine whether the user can delete the job poster.
75
     *
76
     * @param \App\Models\User      $user      User object making the request.
77
     * @param \App\Models\JobPoster $jobPoster Job Poster object being acted upon.
78
     *
79
     * @return boolean
80
     */
81
    public function delete(User $user, JobPoster $jobPoster) : bool
82
    {
83
        // Jobs can only be deleted when they're in the 'draft'
84
        // state, and only by managers that created them.
85
        return $user->user_role->name == 'manager' &&
86
            $jobPoster->manager->user->id == $user->id &&
87
            !$jobPoster->published;
88
    }
89
90
    /**
91
     * Determine whether the user can restore the job poster.
92
     *
93
     * @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...
94
     * @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...
95
     * @return mixed
96
     */
97
    public function restore(User $user, JobPoster $jobPoster)
0 ignored issues
show
Unused Code introduced by
The parameter $jobPoster 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

97
    public function restore(User $user, /** @scrutinizer ignore-unused */ JobPoster $jobPoster)

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

97
    public function restore(/** @scrutinizer ignore-unused */ User $user, JobPoster $jobPoster)

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...
98
    {
99
        //
100
    }
101
102
    /**
103
     * Determine whether the user can permanently delete the job poster.
104
     *
105
     * @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...
106
     * @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...
107
     * @return mixed
108
     */
109
    public function forceDelete(User $user, JobPoster $jobPoster)
0 ignored issues
show
Unused Code introduced by
The parameter $jobPoster 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

109
    public function forceDelete(User $user, /** @scrutinizer ignore-unused */ JobPoster $jobPoster)

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

109
    public function forceDelete(/** @scrutinizer ignore-unused */ User $user, JobPoster $jobPoster)

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...
110
    {
111
        //
112
    }
113
}
114