Passed
Push — master ( 26caeb...0e28f7 )
by Thomas
11:18
created

CommentPolicy   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 3
c 2
b 0
f 0
dl 0
loc 21
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 2 1
A store_student_comment() 0 3 2
1
<?php
2
3
namespace App\Models\Policies;
4
5
use App\Models\Student;
6
use App\Models\User;
7
use Illuminate\Auth\Access\HandlesAuthorization;
8
9
class CommentPolicy
10
{
11
    use HandlesAuthorization;
12
13
    /**
14
     * Create a new policy instance.
15
     *
16
     * @return void
17
     */
18
    public function __construct()
19
    {
20
        //
21
    }
22
23
    /**
24
     * the user may add a comment for students who are enrolled in one of their courses,
25
     * or to any student if they have explicit permission to do so.
26
     */
27
    public function store_student_comment(User $user, Student $student)
28
    {
29
        return ($student->enrollments()->whereHas('course', fn ($q) => $q->where('teacher_id', $user->teacher_id))->count() > 0) || $user->can('comments.edit');
30
    }
31
}
32