Passed
Push — feature/job-builder/step-03-ui ( dabf2e...dabf2e )
by Xander
20:05 queued 13s
created

AssessmentPolicy::delete()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 5
ccs 0
cts 3
cp 0
rs 10
cc 2
nc 2
nop 2
crap 6
1
<?php
2
3
namespace App\Policies;
4
5
use App\Models\User;
6
use App\Models\Assessment;
7
use App\Policies\BasePolicy;
8
9
class AssessmentPolicy extends BasePolicy
10
{
11
12
    /**
13
     * Determine whether the user can view the Assessment.
14
     *
15
     * @param  \App\Models\User       $user
1 ignored issue
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
16
     * @param  \App\Models\Assessment $assessment
1 ignored issue
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
17
     * @return boolean
18
     */
19
    public function view(User $user, Assessment $assessment): bool
20
    {
21
        // Managers can view assessments tied to Jobs they own.
22
        return $user->hasRole('manager') &&
23
            $assessment->criterion->job_poster->manager->user_id === $user->id;
24
    }
25
26
    /**
27
     * Determine whether the user can create Assessments.
28
     *
29
     * @param  \App\Models\User $user
1 ignored issue
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
30
     * @return boolean
31
     */
32
    public function create(User $user): bool
33
    {
34
        //Any manager can create a new Assessment, but only for criteria they own.
0 ignored issues
show
Coding Style introduced by
No space found before comment text; expected "// Any manager can create a new Assessment, but only for criteria they own." but found "//Any manager can create a new Assessment, but only for criteria they own."
Loading history...
35
        return $user->hasRole('manager');
36
    }
37
38
    /**
39
     * Determine whether the user can update the Assessment
40
     *
41
     * @param  \App\Models\User       $user
1 ignored issue
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
42
     * @param  \App\Models\Assessment $assessment
1 ignored issue
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
43
     * @return boolean
44
     */
45
    public function update(User $user, Assessment $assessment): bool
46
    {
47
        // Managers can edit assessments tied to Jobs they own.
48
        return $user->hasRole('manager') &&
49
            $assessment->criterion->job_poster->manager->user_id === $user->id;
50
    }
51
52
    /**
53
     * Determine whether the user can delete the job poster.
54
     *
55
     * @param \App\Models\User       $user       User object making the request.
56
     * @param \App\Models\Assessment $assessment Job Poster object being acted upon.
57
     *
58
     * @return boolean
59
     */
60
    public function delete(User $user, Assessment $assessment) : bool
61
    {
62
        // Managers can delete assessments tied to Jobs they own.
63
        return $user->hasRole('manager') &&
64
            $assessment->criterion->job_poster->manager->user_id === $user->id;
65
    }
66
}
67