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

GroupRepository::getModel()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php namespace App\Modules\V1\Acl\Repositories;
2
3
use App\Modules\V1\Core\AbstractRepositories\AbstractRepository;
4
5
class GroupRepository extends AbstractRepository
6
{
7
	/**
8
	 * Return the model full namespace.
9
	 * 
10
	 * @return string
11
	 */
12
	protected function getModel()
13
	{
14
		return 'App\Modules\V1\Acl\AclGroup';
15
	}
16
17
	/**
18
	 * Assign the given permission ids to the given group.
19
	 * 
20
	 * @param  integer $groupId    
21
	 * @param  array   $permissionIds
22
	 * @return object
23
	 */
24 View Code Duplication
	public function assignPermissions($groupId, $permissionIds)
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...
25
	{
26
		\DB::transaction(function () use ($groupId, $permissionIds) {
27
			$group = $this->find($groupId);
28
			$group->permissions()->detach();
29
			$group->permissions()->attach($permissionIds);
30
		});
31
32
        return $this->find($group_id);
0 ignored issues
show
Bug introduced by
The variable $group_id does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
33
	}
34
35
	/**
36
     *  Return the users in the given group in pages.
37
     * 
38
     * @param  integer $groupId
39
     * @param  integer $perPage
40
     * @param  array   $relations
41
     * @param  string  $sortBy
42
     * @param  boolean $desc
43
     * @return collection
44
     */
45
    public function users($groupId, $perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 1)
46
    {
47
		$group = $this->find($groupId);
48
		$sort  = $desc ? 'desc' : 'asc';
49
50
        return $group->users()->with($relations)->orderBy($sortBy, $sort)->paginate($perPage);
51
    }
52
}
53