Passed
Branch master (cd4548)
by Fèvre
19:36
created

DiscussConversationPolicy::delete()   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
namespace Xetaravel\Policies;
3
4
use Xetaravel\Models\User;
5
use Xetaravel\Models\DiscussConversation;
6
use Illuminate\Auth\Access\HandlesAuthorization;
7
8
class DiscussConversationPolicy
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.discuss.conversations')) {
23
            return true;
24
        }
25
    }
26
27
    /**
28
     * Determine whether the user can update the discuss conversation.
29
     *
30
     * @param \Xetaravel\Models\User $user
31
     * @param \Xetaravel\Models\DiscussConversation $discussConversation
32
     *
33
     * @return bool
34
     */
35
    public function update(User $user, DiscussConversation $discussConversation)
36
    {
37
        return $user->id === $discussConversation->user_id;
38
    }
39
40
    /**
41
     * Determine whether the user can delete the discuss conversation.
42
     *
43
     * @param \Xetaravel\Models\User $user
44
     * @param \Xetaravel\Models\DiscussConversation $discussConversation
45
     *
46
     * @return bool
47
     */
48
    public function delete(User $user, DiscussConversation $discussConversation)
49
    {
50
        return $user->id === $discussConversation->user_id;
51
    }
52
53
    /**
54
     * Determine whether the user can make a discuss post as solved.
55
     * User must be the creator of the conversation to be able to make a
56
     * post as solved.
57
     *
58
     * @param \Xetaravel\Models\User $user
59
     * @param \Xetaravel\Models\DiscussConversation $discussConversation
60
     *
61
     * @return bool
62
     */
63
    public function solved(User $user, DiscussConversation $discussConversation)
64
    {
65
        return $user->id === $discussConversation->user_id;
66
    }
67
}
68