This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
|||||||||||
2 | ||||||||||||
3 | namespace Mamikon\RoleManager; |
|||||||||||
4 | ||||||||||||
5 | ||||||||||||
6 | use Illuminate\Foundation\Auth\User; |
|||||||||||
7 | use Illuminate\Support\Facades\Gate; |
|||||||||||
8 | use Illuminate\Support\Facades\Schema; |
|||||||||||
9 | use Mamikon\RoleManager\Models\Permissions; |
|||||||||||
10 | use Mamikon\RoleManager\Models\Roles; |
|||||||||||
11 | ||||||||||||
12 | /** |
|||||||||||
13 | * Class RoleManager |
|||||||||||
14 | * |
|||||||||||
15 | * @category Laravel_Package |
|||||||||||
16 | * @package Mamikon\RoleManager |
|||||||||||
17 | * @author Mamikon Arakelyan <[email protected]> |
|||||||||||
18 | * @license https://github.com/mamikon/role-manager/blob/master/LICENSE.md MIT |
|||||||||||
19 | * @link https://github.com/mamikon/role-manager |
|||||||||||
20 | */ |
|||||||||||
21 | class RoleManager |
|||||||||||
22 | { |
|||||||||||
23 | /** |
|||||||||||
24 | * Define all permission and make usable from laravel application |
|||||||||||
25 | * |
|||||||||||
26 | * @return bool |
|||||||||||
27 | */ |
|||||||||||
28 | public function defineAllPermissions() |
|||||||||||
29 | { |
|||||||||||
30 | foreach ($this->getPermissions() as $permission) { |
|||||||||||
31 | ||||||||||||
32 | Gate::define( |
|||||||||||
33 | $permission->name, |
|||||||||||
34 | function ($user, ...$arguments) use ($permission) { |
|||||||||||
35 | foreach ($permission->roles as $role) { |
|||||||||||
36 | if ($role->belongsToUser($user)) { |
|||||||||||
37 | if (!empty($permission->class) |
|||||||||||
38 | AND !empty($permission->method) |
|||||||||||
0 ignored issues
–
show
|
||||||||||||
39 | AND class_exists($permission->class) |
|||||||||||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
Using logical operators such as
and instead of && is generally not recommended.
PHP has two types of connecting operators (logical operators, and boolean operators):
The difference between these is the order in which they are executed. In most cases,
you would want to use a boolean operator like Let’s take a look at a few examples: // Logical operators have lower precedence:
$f = false or true;
// is executed like this:
($f = false) or true;
// Boolean operators have higher precedence:
$f = false || true;
// is executed like this:
$f = (false || true);
Logical Operators are used for Control-FlowOne case where you explicitly want to use logical operators is for control-flow such as this: $x === 5
or die('$x must be 5.');
// Instead of
if ($x !== 5) {
die('$x must be 5.');
}
Since // The following is currently a parse error.
$x === 5
or throw new RuntimeException('$x must be 5.');
These limitations lead to logical operators rarely being of use in current PHP code. ![]() |
||||||||||||
40 | ) { |
|||||||||||
41 | $container = resolve($permission->class); |
|||||||||||
42 | if (method_exists($container, $permission->method)) { |
|||||||||||
43 | array_unshift($arguments, $user); |
|||||||||||
44 | return |
|||||||||||
45 | call_user_func_array( |
|||||||||||
46 | [$container, $permission->method], |
|||||||||||
47 | $arguments |
|||||||||||
48 | ); |
|||||||||||
49 | } else { |
|||||||||||
50 | return false; |
|||||||||||
51 | } |
|||||||||||
52 | } |
|||||||||||
53 | return true; |
|||||||||||
54 | } |
|||||||||||
55 | } |
|||||||||||
56 | return false; |
|||||||||||
57 | } |
|||||||||||
58 | ); |
|||||||||||
59 | } |
|||||||||||
60 | return false; |
|||||||||||
61 | } |
|||||||||||
62 | ||||||||||||
63 | /** |
|||||||||||
64 | * Assign Role to user |
|||||||||||
65 | * |
|||||||||||
66 | * @param int|User $user User Instance or user id |
|||||||||||
67 | * @param int|string|Roles $role Role Instance, role name, or role id |
|||||||||||
68 | * |
|||||||||||
69 | * @return bool |
|||||||||||
70 | */ |
|||||||||||
71 | View Code Duplication | public function assignRole($user, $role) |
||||||||||
0 ignored issues
–
show
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. ![]() |
||||||||||||
72 | { |
|||||||||||
73 | if (is_int($user) and !$user = User::where('id', $user)->first()) { |
|||||||||||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
Using logical operators such as
and instead of && is generally not recommended.
PHP has two types of connecting operators (logical operators, and boolean operators):
The difference between these is the order in which they are executed. In most cases,
you would want to use a boolean operator like Let’s take a look at a few examples: // Logical operators have lower precedence:
$f = false or true;
// is executed like this:
($f = false) or true;
// Boolean operators have higher precedence:
$f = false || true;
// is executed like this:
$f = (false || true);
Logical Operators are used for Control-FlowOne case where you explicitly want to use logical operators is for control-flow such as this: $x === 5
or die('$x must be 5.');
// Instead of
if ($x !== 5) {
die('$x must be 5.');
}
Since // The following is currently a parse error.
$x === 5
or throw new RuntimeException('$x must be 5.');
These limitations lead to logical operators rarely being of use in current PHP code. ![]() |
||||||||||||
74 | return false; |
|||||||||||
75 | } |
|||||||||||
76 | if (is_int($role) and !$role = Roles::where('id', $role)->first()) { |
|||||||||||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
Using logical operators such as
and instead of && is generally not recommended.
PHP has two types of connecting operators (logical operators, and boolean operators):
The difference between these is the order in which they are executed. In most cases,
you would want to use a boolean operator like Let’s take a look at a few examples: // Logical operators have lower precedence:
$f = false or true;
// is executed like this:
($f = false) or true;
// Boolean operators have higher precedence:
$f = false || true;
// is executed like this:
$f = (false || true);
Logical Operators are used for Control-FlowOne case where you explicitly want to use logical operators is for control-flow such as this: $x === 5
or die('$x must be 5.');
// Instead of
if ($x !== 5) {
die('$x must be 5.');
}
Since // The following is currently a parse error.
$x === 5
or throw new RuntimeException('$x must be 5.');
These limitations lead to logical operators rarely being of use in current PHP code. ![]() |
||||||||||||
77 | return false; |
|||||||||||
78 | } |
|||||||||||
79 | if (is_string($role) and !$role = Roles::where('name', $role)->first()) { |
|||||||||||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
Using logical operators such as
and instead of && is generally not recommended.
PHP has two types of connecting operators (logical operators, and boolean operators):
The difference between these is the order in which they are executed. In most cases,
you would want to use a boolean operator like Let’s take a look at a few examples: // Logical operators have lower precedence:
$f = false or true;
// is executed like this:
($f = false) or true;
// Boolean operators have higher precedence:
$f = false || true;
// is executed like this:
$f = (false || true);
Logical Operators are used for Control-FlowOne case where you explicitly want to use logical operators is for control-flow such as this: $x === 5
or die('$x must be 5.');
// Instead of
if ($x !== 5) {
die('$x must be 5.');
}
Since // The following is currently a parse error.
$x === 5
or throw new RuntimeException('$x must be 5.');
These limitations lead to logical operators rarely being of use in current PHP code. ![]() |
||||||||||||
80 | return false; |
|||||||||||
81 | } |
|||||||||||
82 | if (!($user instanceof User) or !($role instanceof Roles)) { |
|||||||||||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
Using logical operators such as
or instead of || is generally not recommended.
PHP has two types of connecting operators (logical operators, and boolean operators):
The difference between these is the order in which they are executed. In most cases,
you would want to use a boolean operator like Let’s take a look at a few examples: // Logical operators have lower precedence:
$f = false or true;
// is executed like this:
($f = false) or true;
// Boolean operators have higher precedence:
$f = false || true;
// is executed like this:
$f = (false || true);
Logical Operators are used for Control-FlowOne case where you explicitly want to use logical operators is for control-flow such as this: $x === 5
or die('$x must be 5.');
// Instead of
if ($x !== 5) {
die('$x must be 5.');
}
Since // The following is currently a parse error.
$x === 5
or throw new RuntimeException('$x must be 5.');
These limitations lead to logical operators rarely being of use in current PHP code. ![]() |
||||||||||||
83 | return false; |
|||||||||||
84 | } |
|||||||||||
85 | return $role->assignToUser($user); |
|||||||||||
86 | } |
|||||||||||
87 | ||||||||||||
88 | /** |
|||||||||||
89 | * Remove Role from user |
|||||||||||
90 | * |
|||||||||||
91 | * @param int|User $user User Instance or user id |
|||||||||||
92 | * @param int|string|Roles $role Role Instance, role name, or role id |
|||||||||||
93 | * |
|||||||||||
94 | * @return bool |
|||||||||||
95 | */ |
|||||||||||
96 | View Code Duplication | public function removeRole($user, $role) |
||||||||||
0 ignored issues
–
show
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. ![]() |
||||||||||||
97 | { |
|||||||||||
98 | if (is_int($user) and !$user = User::where('id', $user)->first()) { |
|||||||||||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
Using logical operators such as
and instead of && is generally not recommended.
PHP has two types of connecting operators (logical operators, and boolean operators):
The difference between these is the order in which they are executed. In most cases,
you would want to use a boolean operator like Let’s take a look at a few examples: // Logical operators have lower precedence:
$f = false or true;
// is executed like this:
($f = false) or true;
// Boolean operators have higher precedence:
$f = false || true;
// is executed like this:
$f = (false || true);
Logical Operators are used for Control-FlowOne case where you explicitly want to use logical operators is for control-flow such as this: $x === 5
or die('$x must be 5.');
// Instead of
if ($x !== 5) {
die('$x must be 5.');
}
Since // The following is currently a parse error.
$x === 5
or throw new RuntimeException('$x must be 5.');
These limitations lead to logical operators rarely being of use in current PHP code. ![]() |
||||||||||||
99 | return false; |
|||||||||||
100 | } |
|||||||||||
101 | if (is_int($role) and !$role = Roles::where('id', $role)->first()) { |
|||||||||||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
Using logical operators such as
and instead of && is generally not recommended.
PHP has two types of connecting operators (logical operators, and boolean operators):
The difference between these is the order in which they are executed. In most cases,
you would want to use a boolean operator like Let’s take a look at a few examples: // Logical operators have lower precedence:
$f = false or true;
// is executed like this:
($f = false) or true;
// Boolean operators have higher precedence:
$f = false || true;
// is executed like this:
$f = (false || true);
Logical Operators are used for Control-FlowOne case where you explicitly want to use logical operators is for control-flow such as this: $x === 5
or die('$x must be 5.');
// Instead of
if ($x !== 5) {
die('$x must be 5.');
}
Since // The following is currently a parse error.
$x === 5
or throw new RuntimeException('$x must be 5.');
These limitations lead to logical operators rarely being of use in current PHP code. ![]() |
||||||||||||
102 | return false; |
|||||||||||
103 | } |
|||||||||||
104 | if (is_string($role) and !$role = Roles::where('name', $role)->first()) { |
|||||||||||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
Using logical operators such as
and instead of && is generally not recommended.
PHP has two types of connecting operators (logical operators, and boolean operators):
The difference between these is the order in which they are executed. In most cases,
you would want to use a boolean operator like Let’s take a look at a few examples: // Logical operators have lower precedence:
$f = false or true;
// is executed like this:
($f = false) or true;
// Boolean operators have higher precedence:
$f = false || true;
// is executed like this:
$f = (false || true);
Logical Operators are used for Control-FlowOne case where you explicitly want to use logical operators is for control-flow such as this: $x === 5
or die('$x must be 5.');
// Instead of
if ($x !== 5) {
die('$x must be 5.');
}
Since // The following is currently a parse error.
$x === 5
or throw new RuntimeException('$x must be 5.');
These limitations lead to logical operators rarely being of use in current PHP code. ![]() |
||||||||||||
105 | return false; |
|||||||||||
106 | } |
|||||||||||
107 | if (!($user instanceof User) or !($role instanceof Roles)) { |
|||||||||||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
Using logical operators such as
or instead of || is generally not recommended.
PHP has two types of connecting operators (logical operators, and boolean operators):
The difference between these is the order in which they are executed. In most cases,
you would want to use a boolean operator like Let’s take a look at a few examples: // Logical operators have lower precedence:
$f = false or true;
// is executed like this:
($f = false) or true;
// Boolean operators have higher precedence:
$f = false || true;
// is executed like this:
$f = (false || true);
Logical Operators are used for Control-FlowOne case where you explicitly want to use logical operators is for control-flow such as this: $x === 5
or die('$x must be 5.');
// Instead of
if ($x !== 5) {
die('$x must be 5.');
}
Since // The following is currently a parse error.
$x === 5
or throw new RuntimeException('$x must be 5.');
These limitations lead to logical operators rarely being of use in current PHP code. ![]() |
||||||||||||
108 | return false; |
|||||||||||
109 | } |
|||||||||||
110 | $role->users()->detach($user->id); |
|||||||||||
111 | return true; |
|||||||||||
112 | } |
|||||||||||
113 | ||||||||||||
114 | /** |
|||||||||||
115 | * Get All permissions |
|||||||||||
116 | * |
|||||||||||
117 | * @return array|\Illuminate\Database\Eloquent\Collection|static[] |
|||||||||||
118 | */ |
|||||||||||
119 | public function getPermissions() |
|||||||||||
120 | { |
|||||||||||
121 | if (Schema::hasTable(config('roleManager.permissionsTable'))) { |
|||||||||||
122 | return Permissions::with('roles')->get(); |
|||||||||||
0 ignored issues
–
show
The method
get does only exist in Illuminate\Database\Eloquent\Builder , but not in Illuminate\Database\Eloquent\Model .
It seems like the method you are trying to call exists only in some of the possible types. Let’s take a look at an example: class A
{
public function foo() { }
}
class B extends A
{
public function bar() { }
}
/**
* @param A|B $x
*/
function someFunction($x)
{
$x->foo(); // This call is fine as the method exists in A and B.
$x->bar(); // This method only exists in B and might cause an error.
}
Available Fixes
![]() |
||||||||||||
123 | } |
|||||||||||
124 | return []; |
|||||||||||
125 | } |
|||||||||||
126 | ||||||||||||
127 | } |
PHP has two types of connecting operators (logical operators, and boolean operators):
and
&&
or
||
The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like
&&
, or||
.Let’s take a look at a few examples:
Logical Operators are used for Control-Flow
One case where you explicitly want to use logical operators is for control-flow such as this:
Since
die
introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined withthrow
at this point:These limitations lead to logical operators rarely being of use in current PHP code.