Issues (75)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

src/Controllers/RoleController.php (10 issues)

Upgrade to new PHP Analysis Engine

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\Controllers;
4
5
use App\Http\Controllers\Controller;
6
use Illuminate\Http\Request;
7
use Mamikon\RoleManager\Models\Permissions;
8
use Mamikon\RoleManager\Models\Roles;
9
use Mamikon\RoleManager\Requests\RoleRequest;
10
11
/**
12
 * Class RoleController
13
 *
14
 * @category Laravel_Package
15
 * @package  Mamikon\RoleManager
16
 * @author   Mamikon Arakelyan <[email protected]>
17
 * @license  https://github.com/mamikon/role-manager/blob/master/LICENSE.md MIT
18
 * @link     https://github.com/mamikon/role-manager
19
 */
20
class RoleController extends Controller
21
{
22
    /**
23
     * Display a listing of the resource.
24
     *
25
     * @param Request $request
26
     *
27
     * @return \Illuminate\Http\Response
28
     */
29 View Code Duplication
    public function index(Request $request)
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.

Loading history...
30
    {
31
        $this->authorize('view_role');
32
        if (!empty($request->term)) {
33
            $term = trim($request->term);
34
            $roles = Roles::where('name', 'like', '%' . $term . '%')
35
                ->orWhere('description', 'like', '%' . $term . '%')
36
                ->paginate(config('roleManager.rolesPerPage'));
37
38
        } else {
39
            $roles = Roles::paginate(config('roleManager.rolesPerPage'));
40
        }
41
        return view('RoleManager::role.index', ['roles' => $roles]);
42
    }
43
44
    /**
45
     * Show the form for creating a new resource.
46
     *
47
     * @return \Illuminate\Http\Response
48
     */
49
    public function create()
50
    {
51
        $this->authorize('create_role');
52
53
        return view(
54
            'RoleManager::role.create',
55
            ['permissions' => Permissions::all()]
56
        );
57
    }
58
59
    /**
60
     * Store a newly created resource in storage.
61
     *
62
     * @param Request|RoleRequest $request
63
     *
64
     * @return \Illuminate\Http\Response
65
     */
66
    public function store(RoleRequest $request)
67
    {
68
        $this->authorize('create_role');
69
70
        $role = Roles::create($request->all());
71 View Code Duplication
        if (!empty($request->permission) AND is_array($request->permission)) {
0 ignored issues
show
This code seems to be duplicated across 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...
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):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning 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 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-Flow

One 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 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 with throw at this point:

// 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.

Loading history...
The property permission does not exist on object<Mamikon\RoleManager\Requests\RoleRequest>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?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.

Loading history...
72
            foreach ($request->permission as $permission) {
0 ignored issues
show
The property permission does not exist on object<Mamikon\RoleManager\Requests\RoleRequest>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?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.

Loading history...
73
                $role->permissions()->attach($permission);
74
            }
75
        }
76
        $request->session()->flash('message', 'Role Successfully Created');
77
        return redirect()->route('RoleManager::role.edit', $role->id);
78
    }
79
80
81
    /**
82
     * Show the form for editing the specified resource.
83
     *
84
     * @param Roles $role
85
     *
86
     * @return \Illuminate\Http\Response
87
     */
88
    public function edit(Roles $role)
89
    {
90
        $this->authorize('edit_role');
91
92
        $valueList = $role->permissions()->get()->pluck('id')->toArray();
93
        return view(
94
            'RoleManager::role.edit',
95
            ['role' => $role, 'permissions' => Permissions::all(),
96
                'valueList' => $valueList]
97
        );
98
    }
99
100
    /**
101
     * Update the specified resource in storage.
102
     *
103
     * @param Request|RoleRequest $request
104
     * @param int                 $id
105
     *
106
     * @return \Illuminate\Http\Response
107
     */
108
    public function update(RoleRequest $request, $id)
109
    {
110
        $this->authorize('edit_role');
111
112
        $role = Roles::where('id', $id)->firstOrFail();
113
        $role->update($request->all());
114 View Code Duplication
        if (!empty($request->permission) AND is_array($request->permission)) {
0 ignored issues
show
This code seems to be duplicated across 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...
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):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning 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 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-Flow

One 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 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 with throw at this point:

// 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.

Loading history...
The property permission does not exist on object<Mamikon\RoleManager\Requests\RoleRequest>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?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.

Loading history...
115
            $role->permissions()->sync($request->permission);
0 ignored issues
show
The property permission does not exist on object<Mamikon\RoleManager\Requests\RoleRequest>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?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.

Loading history...
116
117
        } else {
118
            $role->permissions()->detach();
119
        }
120
        $request->session()->flash('message', 'Role Updated Successfully');
121
        return redirect()->route('RoleManager::role.edit', $role->id);
122
    }
123
124
    /**
125
     * Remove the specified resource from storage.
126
     *
127
     * @param int $id
128
     *
129
     * @return \Illuminate\Http\Response
130
     */
131 View Code Duplication
    public function destroy($id)
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.

Loading history...
132
    {
133
        $this->authorize('delete_role');
134
135
        Roles::where('id', $id)->delete();
136
        session()->flash('message', 'Role Deleted Successfully');
137
        session()->flash('message-status', 'alert-info');
138
        return redirect()->route('RoleManager::role.index');
139
    }
140
}
141