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

ProjectPolicy::before()   A

Complexity

Conditions 4
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 7
Ratio 100 %

Importance

Changes 0
Metric Value
dl 7
loc 7
rs 9.2
c 0
b 0
f 0
cc 4
eloc 4
nc 2
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\ProjectAccess;
16
use Tinyissue\Model\Project;
17
use Tinyissue\Model\User;
18
use Illuminate\Auth\Access\HandlesAuthorization;
19
20
/**
21
 * Class ProjectPolicy.
22
 * View:   member of the project and manager role.
23
 * Create: admin role.
24
 * Update: admin role.
25
 * Delete: admin role.
26
 *
27
 * @author Mohamed Alsharaf <[email protected]>
28
 */
29
class ProjectPolicy
30
{
31
    use HandlesAuthorization, ProjectAccess;
32
33 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...
34
    {
35
        $this->dd(__METHOD__);
0 ignored issues
show
Bug introduced by
The method dd() does not seem to exist on object<Tinyissue\Policies\ProjectPolicy>.

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...
36
        if ($user instanceof UserInterface && ($user->isAdmin() || $user->isManager())) {
37
            return true;
38
        }
39
    }
40
41
    /**
42
     * Determine whether the user can view the project.
43
     *
44
     * @param  User  $user
45
     * @param  Project  $project
46
     * @return mixed
47
     */
48 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...
49
    {
50
        if ($this->isPublicProject($project) || $project->isMember($user->id)) {
51
            return true;
52
        }
53
54
        return false;
55
    }
56
57
58
    /**
59
     * Determine whether the user can create projects.
60
     *
61
     * @param  User  $user
62
     * @return mixed
63
     */
64
    public function create(User $user)
65
    {
66
        $this->dd(__METHOD__);
0 ignored issues
show
Bug introduced by
The method dd() does not seem to exist on object<Tinyissue\Policies\ProjectPolicy>.

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...
67
        return $user->isAdmin();
68
    }
69
70
    /**
71
     * Determine whether the user can update the project.
72
     *
73
     * @param  User  $user
74
     * @return mixed
75
     */
76
    public function update(User $user)
77
    {
78
        $this->dd(__METHOD__);
0 ignored issues
show
Bug introduced by
The method dd() does not seem to exist on object<Tinyissue\Policies\ProjectPolicy>.

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

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...
91
        return $this->create($user);
92
    }
93
94
    public function export(User $user)
95
    {
96
        $this->dd(__METHOD__);
0 ignored issues
show
Bug introduced by
The method dd() does not seem to exist on object<Tinyissue\Policies\ProjectPolicy>.

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...
97
        return $user->isAdmin() || $user->isManager();
98
    }
99
100
    public function viewInactiveUsers(User $user, Project $project = null)
0 ignored issues
show
Unused Code introduced by
The parameter $project 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...
101
    {
102
        $this->dd(__METHOD__);
0 ignored issues
show
Bug introduced by
The method dd() does not seem to exist on object<Tinyissue\Policies\ProjectPolicy>.

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...
103
104
        return $user->isUser(); // TODO check this!!!!
105
        $this->dd(__METHOD__);
0 ignored issues
show
Unused Code introduced by
// TODO check this!!!! $this->dd(__METHOD__); does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
106
        if ($this->isPublicProject($project) || $project->isMember($user->id)) {
107
            return true;
108
        }
109
110
        return false;
111
    }
112
    //inactiveUsers
113
}
114