Completed
Push — develop-3.0 ( 4fe777...24fc5d )
by Mohamed
09:15
created

CommentPolicy::update()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 3
nc 3
nop 2
1
<?php
2
3
/*
4
 * This file is part of the Tinyissue package.
5
 *
6
 * (c) Mohamed Alsharaf <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Tinyissue\Policies;
13
14
use Tinyissue\Contracts\Model\UserInterface;
15
use Tinyissue\Extensions\Policies\ProjectAccess;
16
use Tinyissue\Model\Project;
17
use Tinyissue\Model\User;
18
use Tinyissue\Model\Project\Issue\Comment;
19
use Illuminate\Auth\Access\HandlesAuthorization;
20
use Illuminate\Support\Facades\Gate;
21
22
/**
23
 * Class CommentPolicy.
24
 * View:   member of the project and manager role.
25
 * Create: admin role.
26
 * Update: admin role.
27
 * Delete: admin role.
28
 *
29
 * @author Mohamed Alsharaf <[email protected]>
30
 */
31
class CommentPolicy
32
{
33
    use HandlesAuthorization, ProjectAccess;
34
35 View Code Duplication
    public function before(UserInterface $user)
0 ignored issues
show
Duplication introduced by
This method 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...
36
    {
37
        $this->dd(__METHOD__);
0 ignored issues
show
Bug introduced by
The method dd() does not seem to exist on object<Tinyissue\Policies\CommentPolicy>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
38
        if ($user instanceof UserInterface && ($user->isAdmin() || $user->isManager())) {
39
            return true;
40
        }
41
    }
42
43
    /**
44
     * Determine whether the user can view the comment.
45
     *
46
     * @param  User    $user
47
     * @param  Comment $comment
48
     *
49
     * @return mixed
50
     */
51
    public function view(User $user, Comment $comment)
52
    {
53
        return Gate::forUser($user)->allows('view', [$comment->issue, $comment->issue->project]);
54
    }
55
56
    /**
57
     * Determine whether the user can create comments.
58
     *
59
     * @param  User $user
60
     *
61
     * @return mixed
62
     */
63
    public function create(User $user, $comment, Project $project)
0 ignored issues
show
Unused Code introduced by
The parameter $comment 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...
64
    {
65
        return $project->isMember($user->id);
66
    }
67
68
    /**
69
     * Determine whether the user can update the comment.
70
     *
71
     * @param  User    $user
72
     * @param  Comment $comment
73
     *
74
     * @return mixed
75
     */
76
    public function update(User $user, Comment $comment)
77
    {
78
        $this->dd(__METHOD__);
0 ignored issues
show
Bug introduced by
The method dd() does not seem to exist on object<Tinyissue\Policies\CommentPolicy>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
79
        return $user->id === $comment->created_by || ($this->view($user, $comment) && $user->isManagerOrMore());
80
    }
81
82
    /**
83
     * Determine whether the user can delete the comment.
84
     *
85
     * @param  User    $user
86
     * @param  Comment $comment
87
     *
88
     * @return mixed
89
     */
90
    public function delete(User $user, Comment $comment)
91
    {
92
        $this->dd(__METHOD__);
0 ignored issues
show
Bug introduced by
The method dd() does not seem to exist on object<Tinyissue\Policies\CommentPolicy>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
93
        return $this->update($user, $comment);
94
    }
95
}
96