Completed
Pull Request — master (#34)
by Fèvre
05:50 queued 02:49
created

DiscussConversationPolicy   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 45
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 2
dl 45
loc 45
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A before() 6 6 2
A update() 4 4 1
A delete() 4 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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 View Code Duplication
class DiscussConversationPolicy
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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
0 ignored issues
show
Documentation introduced by
Should the return type not be boolean|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
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.

This check looks from 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