Completed
Push — master ( 3a8db8...5050df )
by Sherif
01:59
created

RoleRepository::assignPermissions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10

Duplication

Lines 10
Ratio 100 %

Importance

Changes 0
Metric Value
dl 10
loc 10
rs 9.9332
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php namespace App\Modules\Roles\Repositories;
2
3
use App\Modules\Core\BaseClasses\BaseRepository;
4
use App\Modules\Roles\Role;
5
6
class RoleRepository extends BaseRepository
7
{
8
    /**
9
     * Init new object.
10
     *
11
     * @param   Role $model
12
     * @return  void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
13
     */
14
    public function __construct(Role $model)
15
    {
16
        parent::__construct($model);
17
    }
18
19
    /**
20
     * Assign the given permission ids to the given role.
21
     *
22
     * @param  integer $roleId
23
     * @param  array   $permissionIds
24
     * @return object
25
     */
26 View Code Duplication
    public function assignPermissions($roleId, $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...
27
    {
28
        \DB::transaction(function () use ($roleId, $permissionIds) {
29
            $role = $this->find($roleId);
30
            $role->permissions()->detach();
31
            $role->permissions()->attach($permissionIds);
32
        });
33
34
        return $this->find($roleId);
35
    }
36
}
37