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

NotePolicy::create()   A

Complexity

Conditions 1
Paths 1

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 1
eloc 3
nc 1
nop 1
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\AdminAccess;
16
use Tinyissue\Extensions\Policies\ProjectAccess;
17
use Tinyissue\Model\Project;
18
use Tinyissue\Model\User;
19
use Tinyissue\Model\Project\Note;
20
use Illuminate\Auth\Access\HandlesAuthorization;
21
22
/**
23
 * Class NotePolicy.
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 NotePolicy
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\NotePolicy>.

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 note.
45
     *
46
     * @param  User  $user
47
     * @param  Note  $note
48
     * @return mixed
49
     */
50
//    public function view(User $user, Note $note, Project $project)
51
//    {
52
//        if ($this->isPublicProject($project) || $project->isMember($user->id)) {
53
//            return true;
54
//        }
55
//
56
//        return false;
57
//    }
58 View Code Duplication
    public function view(User $user, Project $project)
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...
59
    {
60
        $this->dd(__METHOD__);
0 ignored issues
show
Bug introduced by
The method dd() does not seem to exist on object<Tinyissue\Policies\NotePolicy>.

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...
61
        if ($this->isPublicProject($project) || $project->isMember($user->id)) {
62
            return true;
63
        }
64
65
        return false;
66
    }
67
68
    /**
69
     * Determine whether the user can create notes.
70
     *
71
     * @param  User  $user
72
     * @return mixed
73
     */
74
    public function create(User $user)
75
    {
76
        $this->dd(__METHOD__);
0 ignored issues
show
Bug introduced by
The method dd() does not seem to exist on object<Tinyissue\Policies\NotePolicy>.

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...
77
        return $user->isManager();
78
    }
79
80
    /**
81
     * Determine whether the user can update the note.
82
     *
83
     * @param  User  $user
84
     * @return mixed
85
     */
86
    public function update(User $user)
87
    {
88
        $this->dd(__METHOD__);
0 ignored issues
show
Bug introduced by
The method dd() does not seem to exist on object<Tinyissue\Policies\NotePolicy>.

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...
89
        return $this->create($user);
90
    }
91
92
    /**
93
     * Determine whether the user can delete the note.
94
     *
95
     * @param  User  $user
96
     * @return mixed
97
     */
98
    public function delete(User $user)
99
    {
100
        $this->dd(__METHOD__);
0 ignored issues
show
Bug introduced by
The method dd() does not seem to exist on object<Tinyissue\Policies\NotePolicy>.

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...
101
        return $this->create($user);
102
    }
103
104
}
105