Passed
Push — feature/create_job__controller ( 068bf5 )
by Tristan
08:15
created

JobPolicy::create()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 2
c 0
b 0
f 0
dl 0
loc 5
rs 10
ccs 0
cts 3
cp 0
cc 1
nc 1
nop 1
crap 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\JobPoster;
7
use Illuminate\Auth\Access\HandlesAuthorization;
8
9
class JobPolicy
0 ignored issues
show
Coding Style introduced by
Missing doc comment for class JobPolicy
Loading history...
10
{
11
    use HandlesAuthorization;
12
13
    /**
14
     * Determine whether the user can view the job poster.
15
     *
16
     * @param  \App\Models\User  $user
0 ignored issues
show
Coding Style introduced by
Expected 6 spaces after parameter type; 2 found
Loading history...
Coding Style introduced by
Missing parameter comment
Loading history...
17
     * @param  \App\Models\JobPoster  $jobPoster
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 2 found
Loading history...
Coding Style introduced by
Missing parameter comment
Loading history...
18
     * @return mixed
0 ignored issues
show
Coding Style introduced by
Tag cannot be grouped with parameter tags in a doc comment
Loading history...
19
     */
20
    public function view(User $user, JobPoster $jobPoster)
21
    {
22
        //Anyone can view a published job
23
        //Only the manager that created it can view an unpublished job
24
        return $jobPoster->published ||
25
            $jobPoster->manager->user->id == $user->id;
26
    }
27
28
    /**
29
     * Determine whether the user can create job posters.
30
     *
31
     * @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...
32
     * @return mixed
0 ignored issues
show
Coding Style introduced by
Tag cannot be grouped with parameter tags in a doc comment
Loading history...
33
     */
34
    public function create(User $user)
35
    {
36
        debugbar()->info('in JobPolicy');
37
        //Any manager can create a new job poster
38
        return $user->user_role->name == 'manager';
39
    }
40
41
    /**
42
     * Determine whether the user can update the job poster.
43
     *
44
     * @param  \App\Models\User  $user
0 ignored issues
show
Coding Style introduced by
Expected 6 spaces after parameter type; 2 found
Loading history...
Coding Style introduced by
Missing parameter comment
Loading history...
45
     * @param  \App\Models\JobPoster  $jobPoster
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 2 found
Loading history...
Coding Style introduced by
Missing parameter comment
Loading history...
46
     * @return mixed
0 ignored issues
show
Coding Style introduced by
Tag cannot be grouped with parameter tags in a doc comment
Loading history...
47
     */
48
    public function update(User $user, JobPoster $jobPoster)
49
    {
50
        //Only managers can edit jobs, and only their own
51
        return $user->user_role->name == 'manager' &&
52
            $jobPoster->manager->user->id == $user->id;
53
    }
54
55
    /**
56
     * Determine whether the user can delete the job poster.
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\JobPoster  $jobPoster
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 delete(User $user, JobPoster $jobPoster)
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

62
    public function delete(/** @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...
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

62
    public function delete(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...
63
    {
64
        //
65
    }
66
67
    /**
68
     * Determine whether the user can restore the job poster.
69
     *
70
     * @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...
71
     * @param  \App\Models\JobPoster  $jobPoster
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...
72
     * @return mixed
0 ignored issues
show
Coding Style introduced by
Tag cannot be grouped with parameter tags in a doc comment
Loading history...
73
     */
74
    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

74
    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

74
    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...
75
    {
76
        //
77
    }
78
79
    /**
80
     * Determine whether the user can permanently delete the job poster.
81
     *
82
     * @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...
83
     * @param  \App\Models\JobPoster  $jobPoster
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 2 found
Loading history...
Coding Style introduced by
Missing parameter comment
Loading history...
84
     * @return mixed
0 ignored issues
show
Coding Style introduced by
Tag cannot be grouped with parameter tags in a doc comment
Loading history...
85
     */
86
    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

86
    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

86
    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...
87
    {
88
        //
89
    }
90
}
91