Issues (264)

app/Policies/BlogCommentPolicy.php (1 issue)

Severity
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Xetaravel\Policies;
6
7
use Xetaravel\Models\BlogArticle;
8
use Xetaravel\Models\User;
9
use Xetaravel\Models\BlogComment;
10
use Illuminate\Auth\Access\HandlesAuthorization;
11
12
class BlogCommentPolicy
13
{
14
    use HandlesAuthorization;
15
16
    /**
17
     * Authorize all actions if the user has the given permission.
18
     *
19
     * @param User $user
20
     * @param string $ability
21
     *
22
     * @return true|void
23
     */
24
    public function before(User $user, string $ability)
0 ignored issues
show
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

24
    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...
25
    {
26
        if ($user->hasPermissionTo('manage blog comment')) {
27
            return true;
28
        }
29
    }
30
31
    /**
32
     * Determine whether the user can create a blog comment.
33
     *
34
     * @param User $user
35
     * @param BlogArticle $article
36
     * @return bool
37
     */
38
    public function create(User $user, BlogArticle $article): bool
39
    {
40
        return $article->published_at <= now() &&
41
            $user->hasPermissionTo('create blog comment');
42
    }
43
44
    /**
45
     * Determine whether the user can update a blog comment.
46
     *
47
     * @param User $user
48
     * @param BlogComment $comment
49
     *
50
     * @return bool
51
     */
52
    public function update(User $user, BlogComment $comment): bool
53
    {
54
        return $user->id === $comment->user_id &&
55
            $user->hasPermissionTo('update blog comment');
56
    }
57
58
    /**
59
     * Determine whether the user can delete a blog comment.
60
     *
61
     * @param User $user
62
     * @param BlogComment $comment
63
     * @param BlogArticle $article
64
     *
65
     * @return bool
66
     */
67
    public function delete(User $user, BlogComment $comment, BlogArticle $article): bool
68
    {
69
        return $user->id === $comment->user_id &&
70
            $article->id === $comment->blog_article_id &&
71
            $user->hasPermissionTo('delete blog comment');
72
    }
73
}
74