UserPermissionController::createPermission()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 8
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
3
/*
4
 * rmarchiv.tk
5
 * (c) 2016-2017 by Marcel 'ryg' Hering
6
 */
7
8
namespace App\Http\Controllers;
9
10
use App\Models\UserRole;
11
use Illuminate\Http\Request;
12
use App\Models\UserPermission;
13
14
class UserPermissionController extends Controller
15
{
16
    public function createRole()
17
    {
18
        $roles = UserRole::all();
19
20
        return view('users.entrust.addrole', [
21
            'roles' => $roles,
22
        ]);
23
    }
24
25 View Code Duplication
    public function storeRole(Request $request)
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...
26
    {
27
        $r = new UserRole();
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 15 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
28
        $r->name = $request->get('name');
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 9 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
29
        $r->display_name = $request->get('dname');
30
        $r->description = $request->get('desc');
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 2 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
31
        $r->save();
32
33
        return redirect()->action('UserPermissionController@createRole');
34
    }
35
36
    public function createPermission()
37
    {
38
        $perms = UserPermission::all();
39
40
        return view('users.entrust.addperm', [
41
            'perms' => $perms,
42
        ]);
43
    }
44
45 View Code Duplication
    public function storePermission(Request $request)
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...
46
    {
47
        $p = new UserPermission();
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 15 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
48
        $p->name = $request->get('name');
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 9 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
49
        $p->display_name = $request->get('dname');
50
        $p->description = $request->get('desc');
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 2 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
51
        $p->save();
52
53
        return redirect()->action('UserPermissionController@createPermission');
54
    }
55
56
    public function showRole($id)
57
    {
58
        $p = \DB::table('user_permission_role as pr')
59
            ->leftJoin('user_permissions as p', 'pr.permission_id', '=', 'p.id')
60
            ->where('pr.role_id', '=', $id)
61
            ->get();
62
63
        $ptoadd = UserPermission::all();
64
65
        return view('users.entrust.showrole', [
66
            'perms'      => $p,
67
            'roleid'     => $id,
68
            'permstoadd' => $ptoadd,
69
        ]);
70
    }
71
72
    public function addPermToRole(Request $request, $roleid)
73
    {
74
        $role = UserRole::all()->where('id', '=', $roleid)->first();
75
        $perm = UserPermission::all()->where('id', '=', $request->get('perm'))->first();
76
77
        $role->attachPermission($perm);
78
79
        return redirect()->action('UserPermissionController@showRole', $roleid);
80
    }
81
82
    public function removePermFromRole($roleid, $permid)
83
    {
84
        $role = UserRole::all()->where('id', '=', $roleid)->first();
85
        $perm = UserPermission::all()->where('id', '=', $permid)->first();
86
87
        $role->detachPermission($perm);
88
89
        return redirect()->action('UserPermissionController@showRole', $roleid);
90
    }
91
92
    public function showPermission($id)
0 ignored issues
show
Unused Code introduced by
The parameter $id 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...
93
    {
94
    }
95
}
96