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

TagPolicy   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 92
Duplicated Lines 7.61 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 4
dl 7
loc 92
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A before() 7 7 4
A view() 0 5 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
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\Role;
18
use Tinyissue\Model\Tag;
19
use Tinyissue\Model\User;
20
use Illuminate\Auth\Access\HandlesAuthorization;
21
22
/**
23
 * Class ProjectPolicy.
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 TagPolicy
32
{
33
    use HandlesAuthorization;
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\TagPolicy>.

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 project.
45
     *
46
     * @param  User  $user
47
     * @param  Project  $project
0 ignored issues
show
Bug introduced by
There is no parameter named $project. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
48
     * @return mixed
49
     */
50
    public function view(User $user, Tag $tag)
51
    {
52
        $this->dd(__METHOD__);
0 ignored issues
show
Bug introduced by
The method dd() does not seem to exist on object<Tinyissue\Policies\TagPolicy>.

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...
53
        return $user->role_id >= $tag->role_limit;
54
    }
55
//
56
//
57
//    /**
58
//     * Whether or not the current user can view this tag.
59
//     *
60
//     * @return bool
61
//     */
62
//    public function canView()
63
//    {
64
//        return $this->getLoggedUser()->role_id >= $this->role_limit;
65
//    }
66
//
67
//    /**
68
//     * Determine whether the user can create projects.
69
//     *
70
//     * @param  User  $user
71
//     * @return mixed
72
//     */
73
//    public function create(User $user)
74
//    {
75
//        $this->dd(__METHOD__);
76
//        return $user->isAdmin();
77
//    }
78
//
79
//    /**
80
//     * Determine whether the user can update the project.
81
//     *
82
//     * @param  User  $user
83
//     * @return mixed
84
//     */
85
//    public function update(User $user)
86
//    {
87
//        $this->dd(__METHOD__);
88
//        return $this->create($user);
89
//    }
90
//
91
//    /**
92
//     * Determine whether the user can delete the project.
93
//     *
94
//     * @param  User  $user
95
//     * @return mixed
96
//     */
97
//    public function delete(User $user)
98
//    {
99
//        $this->dd(__METHOD__);
100
//        return $this->create($user);
101
//    }
102
//
103
//    public function export(User $user)
104
//    {
105
//        $this->dd(__METHOD__);
106
//        return $user->isAdmin() || $user->isManager();
107
//    }
108
//
109
//    public function viewInactiveUsers(User $user, Project $project = null)
110
//    {
111
//        $this->dd(__METHOD__);
112
//
113
//        return $user->isUser(); // TODO check this!!!!
114
//        $this->dd(__METHOD__);
115
//        if ($this->isPublicProject($project) || $project->isMember($user->id)) {
116
//            return true;
117
//        }
118
//
119
//        return false;
120
//    }
121
    //inactiveUsers
122
}
123