PermissionsController::create()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
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
}