Completed
Push — master ( 14a844...cfe0e1 )
by Fèvre
17s queued 17s
created

BlogCommentPolicy::before()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 2
eloc 2
c 1
b 0
f 1
nc 2
nop 2
dl 0
loc 4
rs 10
1
<?php
2
namespace Xetaravel\Policies;
3
4
use Xetaravel\Models\User;
5
use Xetaravel\Models\Comment;
6
use Illuminate\Auth\Access\HandlesAuthorization;
7
8
class BlogCommentPolicy
9
{
10
    use HandlesAuthorization;
11
12
    /**
13
     * Authorize all actions if the user has the given permission.
14
     *
15
     * @param \Xetaravel\Models\User $user
16
     * @param string $ability
17
     *
18
     * @return true|void
19
     */
20
    public function before(User $user, string $ability)
0 ignored issues
show
Unused Code introduced by
The parameter $ability 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

20
    public function before(User $user, /** @scrutinizer ignore-unused */ string $ability)

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...
21
    {
22
        if ($user->hasPermission('manage.blog.comments')) {
23
            return true;
24
        }
25
    }
26
27
    /**
28
     * Determine whether the user can update the discuss post.
29
     *
30
     * @param \Xetaravel\Models\User $user
31
     * @param \Xetaravel\Models\Comment $comment
32
     *
33
     * @return bool
34
     */
35
    public function update(User $user, Comment $comment)
36
    {
37
        return $user->id === $comment->user_id;
38
    }
39
40
    /**
41
     * Determine whether the user can delete the discuss post.
42
     *
43
     * @param \Xetaravel\Models\User $user
44
     * @param \Xetaravel\Models\Comment $comment
45
     *
46
     * @return bool
47
     */
48
    public function delete(User $user, Comment $comment)
49
    {
50
        return $user->id === $comment->user_id;
51
    }
52
}
53