Completed
Push — master ( cd8f65...e1eb39 )
by Sherif
27:44
created

GroupsController::users()   A

Complexity

Conditions 4
Paths 5

Size

Total Lines 8
Code Lines 4

Duplication

Lines 8
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 8
loc 8
rs 9.2
cc 4
eloc 4
nc 5
nop 4
1
<?php
2
namespace App\Modules\V1\Acl\Http\Controllers;
3
4
use Illuminate\Foundation\Http\FormRequest;
5
use App\Modules\V1\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 assignpermissions(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|array|exists:groups,id'
38
            ]);
39
40
        return \Response::json(\Core::groups()->assignPermissions($request->get('group_id'), $request->get('permission_ids')), 200);
41
    }
42
43
     /**
44
     *  Return the users in the given group in pages.
45
     * 
46
     * @param  integer $groupId
47
     * @param  integer $perPage
48
     * @param  string  $sortBy
49
     * @param  boolean $desc
50
     * @return \Illuminate\Http\Response
51
     */
52 View Code Duplication
    public function users($groupId, $perPage = 15, $sortBy = 'created_at', $desc = 1) 
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
        if ($this->model) 
55
        {
56
            $relations = $this->relations && $this->relations['users'] ? $this->relations['users'] : [];
57
            return \Response::json(call_user_func_array("\Core::{$this->model}", [])->users($groupId, $perPage, $relations, $sortBy, $desc), 200);
58
        }
59
    }
60
}
61