Passed
Push — 5.0.0 ( 7b1056...f0e712 )
by Fèvre
05:33
created

BlogCommentPolicy::create()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 2
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Xetaravel\Policies;
4
5
use Xetaravel\Models\User;
6
use Xetaravel\Models\BlogComment;
7
use Illuminate\Auth\Access\HandlesAuthorization;
8
9
class BlogCommentPolicy
10
{
11
    use HandlesAuthorization;
12
13
    /**
14
     * Authorize all actions if the user has the given permission.
15
     *
16
     * @param User $user
17
     * @param string $ability
18
     *
19
     * @return true|void
20
     */
21
    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

21
    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...
22
    {
23
        if ($user->hasPermissionTo('manage blog article')) {
24
            return true;
25
        }
26
    }
27
28
    /**
29
     * Determine whether the user can create a blog comment.
30
     *
31
     * @param User $user
32
     * @param BlogComment $comment
33
     *
34
     * @return bool
35
     */
36
    public function create(User $user, BlogComment $comment): bool
0 ignored issues
show
Unused Code introduced by
The parameter $comment 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

36
    public function create(User $user, /** @scrutinizer ignore-unused */ BlogComment $comment): bool

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...
37
    {
38
        return $user->hasPermissionTo('create blog comment');
39
    }
40
41
    /**
42
     * Determine whether the user can update the discuss post.
43
     *
44
     * @param User $user
45
     * @param BlogComment $comment
46
     *
47
     * @return bool
48
     */
49
    public function update(User $user, BlogComment $comment): bool
50
    {
51
        return $user->id === $comment->user_id;
52
    }
53
54
    /**
55
     * Determine whether the user can delete the discuss post.
56
     *
57
     * @param User $user
58
     * @param BlogComment $comment
59
     *
60
     * @return bool
61
     */
62
    public function delete(User $user, BlogComment $comment): bool
63
    {
64
        return $user->id === $comment->user_id;
65
    }
66
}
67