PermissionsController   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 119
Duplicated Lines 31.93 %

Coupling/Cohesion

Components 1
Dependencies 8

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 11
c 2
b 0
f 1
lcom 1
cbo 8
dl 38
loc 119
ccs 41
cts 41
cp 1
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A index() 0 6 1
A create() 0 4 1
A store() 17 17 2
A edit() 0 10 2
A update() 21 21 3
A delete() 0 14 2

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
 * @package     Dashboard
5
 * @author      Ian Olson <[email protected]>
6
 * @license     MIT
7
 * @copyright   2015, Laraflock
8
 * @link        https://github.com/laraflock
9
 */
10
11
namespace Laraflock\Dashboard\Controllers;
12
13
use Illuminate\Http\Request;
14
use Illuminate\Http\Response;
15
use Laracasts\Flash\Flash;
16
use Laraflock\Dashboard\Exceptions\FormValidationException;
17
use Laraflock\Dashboard\Exceptions\PermissionsException;
18
use Laraflock\Dashboard\Services\Auth\AuthService;
19
use Laraflock\Dashboard\Services\Permission\PermissionService;
20
21
class PermissionsController extends BaseDashboardController
22
{
23
    /**
24
     * Display a listing of the resource.
25
     *
26
     * @return Response
27
     */
28 1
    public function index()
29
    {
30 1
        $permissions = $this->permissionRepositoryInterface->getAll();
31
32 1
        return $this->view('permissions.index')->with(['permissions' => $permissions]);
33
    }
34
35
    /**
36
     * Create a new resource.
37
     *
38
     * @return Response
39
     */
40 1
    public function create()
41
    {
42 1
        return $this->view('permissions.create');
43
    }
44
45
    /**
46
     * Store a newly created resource in storage.
47
     *
48
     * @param Request $request
49
     *
50
     * @return $this|\Illuminate\Http\RedirectResponse
51
     */
52 2 View Code Duplication
    public function store(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...
53
    {
54
        try {
55 2
            $this->permissionRepositoryInterface->create($request->all());
56 2
        } catch (FormValidationException $e) {
57 1
            Flash::error($e->getMessage());
58
59 1
            return redirect()
60 1
              ->route('permissions.create')
61 1
              ->withErrors($e->getErrors())
62 1
              ->withInput();
63
        }
64
65 1
        Flash::success(trans('dashboard::dashboard.flash.permission.create.success'));
66
67 1
        return redirect()->route('permissions.index');
68
    }
69
70
    /**
71
     * Show the form for editing the specified resource.
72
     *
73
     * @param int $id
74
     *
75
     * @return Response
76
     */
77 2
    public function edit($id)
78
    {
79 2
        if (!$permission = $this->permissionRepositoryInterface->getById($id)) {
80 1
            Flash::error(trans('dashboard::dashboard.errors.permission.found'));
81
82 1
            return redirect()->route('permissions.index');
83
        }
84
85 1
        return $this->view('permissions.edit')->with(['permission' => $permission]);
86
    }
87
88
    /**
89
     * Update the specified resource in storage.
90
     *
91
     * @param \Illuminate\Http\Request $request
92
     * @param int                      $id
93
     *
94
     * @return $this|\Illuminate\Http\RedirectResponse
95
     */
96 3 View Code Duplication
    public function update(Request $request, $id)
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...
97
    {
98 1
        try {
99 3
            $this->permissionRepositoryInterface->update($request->all(), $id);
100 3
        } catch (FormValidationException $e) {
101 1
            Flash::error($e->getMessage());
102
103 1
            return redirect()
104 1
              ->route('permissions.edit', ['id' => $id])
105 1
              ->withErrors($e->getErrors())
106 1
              ->withInput();
107 1
        } catch (PermissionsException $e) {
108 1
            Flash::error($e->getMessage());
109
110 1
            return redirect()->route('permissions.index');
111
        }
112
113 1
        Flash::success(trans('dashboard::dashboard.flash.permission.edit.success'));
114
115 1
        return redirect()->route('permissions.edit', ['id' => $id]);
116
    }
117
118
    /**
119
     * Remove the specified resource from storage.
120
     *
121
     * @param int $id
122
     *
123
     * @return \Illuminate\Http\RedirectResponse
124
     */
125 2
    public function delete($id)
126
    {
127
        try {
128 2
            $this->permissionRepositoryInterface->delete($id);
129 2
        } catch (PermissionsException $e) {
130 1
            Flash::error($e->getMessage());
131
132 1
            return redirect()->route('permissions.index');
133
        }
134
135 1
        Flash::success(trans('dashboard::dashboard.flash.permission.delete.success'));
136
137 1
        return redirect()->route('permissions.index');
138
    }
139
}