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 | ||||||||||||
4 | namespace Mamikon\RoleManager\Controllers; |
|||||||||||
5 | ||||||||||||
6 | use App\Http\Controllers\Controller; |
|||||||||||
7 | use Illuminate\Foundation\Auth\User; |
|||||||||||
8 | use Illuminate\Http\Request; |
|||||||||||
9 | use Mamikon\RoleManager\Models\Roles; |
|||||||||||
10 | use Mamikon\RoleManager\Requests\UserRolesRequest; |
|||||||||||
11 | ||||||||||||
12 | /** |
|||||||||||
13 | * Class RoleManagerController |
|||||||||||
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 RoleManagerController extends Controller |
|||||||||||
22 | { |
|||||||||||
23 | /** |
|||||||||||
24 | * List All users |
|||||||||||
25 | * |
|||||||||||
26 | * @param Request $request |
|||||||||||
27 | * |
|||||||||||
28 | * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View |
|||||||||||
29 | */ |
|||||||||||
30 | View Code Duplication | public function index(Request $request) |
||||||||||
0 ignored issues
–
show
|
||||||||||||
31 | { |
|||||||||||
32 | $this->authorize('view_users'); |
|||||||||||
33 | ||||||||||||
34 | if (!empty($request->term)) { |
|||||||||||
35 | $term = trim($request->term); |
|||||||||||
36 | $users = User::where('email', 'like', '%' . $term . '%') |
|||||||||||
37 | ->orWhere('name', 'like', '%' . $term . '%') |
|||||||||||
38 | ->paginate(config('roleManager.usersPerPage')); |
|||||||||||
39 | } else { |
|||||||||||
40 | $users = User::paginate(config('roleManager.usersPerPage')); |
|||||||||||
41 | } |
|||||||||||
42 | return view('RoleManager::index', ['users' => $users]); |
|||||||||||
43 | } |
|||||||||||
44 | ||||||||||||
45 | /** |
|||||||||||
46 | * View User Role Management Form |
|||||||||||
47 | * |
|||||||||||
48 | * @param int $id |
|||||||||||
49 | * |
|||||||||||
50 | * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View |
|||||||||||
51 | */ |
|||||||||||
52 | public function edit($id) |
|||||||||||
53 | { |
|||||||||||
54 | $this->authorize('manage_user_roles'); |
|||||||||||
55 | $user = User::where('id', $id)->firstOrFail(); |
|||||||||||
56 | $roles = Roles::all(); |
|||||||||||
57 | $valueList = array(); |
|||||||||||
58 | if (!empty($roles)) { |
|||||||||||
59 | foreach ($roles as $role) { |
|||||||||||
60 | if ($role->belongsToUser($user)) { |
|||||||||||
61 | $valueList[] = $role->id; |
|||||||||||
62 | } |
|||||||||||
63 | } |
|||||||||||
64 | } |
|||||||||||
65 | return view( |
|||||||||||
66 | 'RoleManager::edit', |
|||||||||||
67 | ['user' => $user, 'roles' => Roles::all(), 'valueList' => $valueList] |
|||||||||||
68 | ); |
|||||||||||
69 | } |
|||||||||||
70 | ||||||||||||
71 | /** |
|||||||||||
72 | * Store changes |
|||||||||||
73 | * |
|||||||||||
74 | * @param UserRolesRequest $request |
|||||||||||
75 | * @param int $id |
|||||||||||
76 | * |
|||||||||||
77 | * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View |
|||||||||||
78 | */ |
|||||||||||
79 | public function update(UserRolesRequest $request, $id) |
|||||||||||
80 | { |
|||||||||||
81 | $this->authorize('manage_user_roles'); |
|||||||||||
82 | $user = User::where('id', $id)->firstOrFail(); |
|||||||||||
0 ignored issues
–
show
$user is not used, you could remove the assignment.
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently. $myVar = 'Value';
$higher = false;
if (rand(1, 6) > 3) {
$higher = true;
} else {
$higher = false;
}
Both the ![]() |
||||||||||||
83 | $roles = Roles::with('users')->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
![]() |
||||||||||||
84 | if (!empty($roles)) { |
|||||||||||
85 | foreach ($roles as $role) { |
|||||||||||
86 | if (!empty($request->role) |
|||||||||||
0 ignored issues
–
show
The property
role does not exist on object<Mamikon\RoleManag...uests\UserRolesRequest> . Since you implemented __get , maybe consider adding a @property annotation.
Since your code implements the magic getter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
If the property has read access only, you can use the @property-read annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property. ![]() |
||||||||||||
87 | AND $role->users->where('id', $id)->count() === 0 |
|||||||||||
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. ![]() |
||||||||||||
88 | AND is_array($request->role) |
|||||||||||
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. ![]() The property
role does not exist on object<Mamikon\RoleManag...uests\UserRolesRequest> . Since you implemented __get , maybe consider adding a @property annotation.
Since your code implements the magic getter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
If the property has read access only, you can use the @property-read annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property. ![]() |
||||||||||||
89 | AND in_array($role->id, $request->role) |
|||||||||||
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. ![]() The property
role does not exist on object<Mamikon\RoleManag...uests\UserRolesRequest> . Since you implemented __get , maybe consider adding a @property annotation.
Since your code implements the magic getter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
If the property has read access only, you can use the @property-read annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property. ![]() |
||||||||||||
90 | ) { |
|||||||||||
91 | $role->users()->attach($id); |
|||||||||||
92 | } elseif ((is_array($request->role) |
|||||||||||
0 ignored issues
–
show
The property
role does not exist on object<Mamikon\RoleManag...uests\UserRolesRequest> . Since you implemented __get , maybe consider adding a @property annotation.
Since your code implements the magic getter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
If the property has read access only, you can use the @property-read annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property. ![]() |
||||||||||||
93 | AND !in_array($role->id, $request->role)) |
|||||||||||
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. ![]() The property
role does not exist on object<Mamikon\RoleManag...uests\UserRolesRequest> . Since you implemented __get , maybe consider adding a @property annotation.
Since your code implements the magic getter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
If the property has read access only, you can use the @property-read annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property. ![]() |
||||||||||||
94 | ) { |
|||||||||||
95 | $role->users()->detach($id); |
|||||||||||
96 | } elseif (empty($request->role)) { |
|||||||||||
0 ignored issues
–
show
The property
role does not exist on object<Mamikon\RoleManag...uests\UserRolesRequest> . Since you implemented __get , maybe consider adding a @property annotation.
Since your code implements the magic getter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
If the property has read access only, you can use the @property-read annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property. ![]() |
||||||||||||
97 | $role->users()->detach(); |
|||||||||||
98 | } |
|||||||||||
99 | } |
|||||||||||
100 | } |
|||||||||||
101 | $request->session()->flash('message', 'User Roles Successfully updated'); |
|||||||||||
102 | return redirect()->route('RoleManager::viewUserRole', $id); |
|||||||||||
0 ignored issues
–
show
$id is of type integer , but the function expects a array .
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
![]() |
||||||||||||
103 | } |
|||||||||||
104 | } |
|||||||||||
105 |
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.