Completed
Push — master ( c7d5ad...0208a8 )
by Sherif
02:59
created

GroupsController   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 34
Duplicated Lines 26.47 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 1
c 1
b 0
f 0
lcom 0
cbo 3
dl 9
loc 34
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A postAssignpermissions() 9 9 1

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
namespace App\Modules\Acl\Http\Controllers\V1;
3
4
use Illuminate\Foundation\Http\FormRequest;
5
use App\Modules\Core\Http\Controllers\BaseApiController;
6
use Illuminate\Http\Request;
7
8
9
class GroupsController extends BaseApiController
10
{
11
    /**
12
     * The name of the model that is used by the base api controller 
13
     * to preform actions like (add, edit ... etc).
14
     * @var string
15
     */
16
    protected $model               = 'groups';
17
18
    /**
19
     * The validations rules used by the base api controller
20
     * to check before add.
21
     * @var array
22
     */
23
    protected $validationRules  = [
24
    'name' => 'required|string|max:100|unique:groups,name,{id}'
25
    ];
26
27
    /**
28
     * Handle an assign permissions to group request.
29
     *
30
     * @param  \Illuminate\Http\Request  $request
31
     * @return \Illuminate\Http\Response
32
     */
33 View Code Duplication
    public function postAssignpermissions(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...
34
    {
35
        $this->validate($request, [
36
            'permission_ids' => 'required|exists:permissions,id', 
37
            'group_id'       => 'required|exists:groups,id'
38
            ]);
39
40
        return \Response::json(\Core::groups()->assignPermissions($request->get('group_id'), $request->get('permission_ids')), 200);
41
    }
42
}
43