Completed
Push — master ( 014612...36ad26 )
by Mahmoud
03:39
created

SyncPermissionsOnRoleAction::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 7

Duplication

Lines 9
Ratio 100 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 9
loc 9
rs 9.6666
cc 1
eloc 7
nc 1
nop 3
1
<?php
2
3
namespace App\Containers\Authorization\Actions;
4
5
use App\Containers\Authorization\Tasks\SyncPermissionsOnRoleTask;
6
use App\Containers\Authorization\Tasks\GetPermissionTask;
7
use App\Containers\Authorization\Tasks\GetRoleTask;
8
use App\Ship\Parents\Actions\Action;
9
10
/**
11
 * Class SyncPermissionsOnRoleAction.
12
 *
13
 * @author Mahmoud Zalt <[email protected]>
14
 */
15 View Code Duplication
class SyncPermissionsOnRoleAction extends Action
0 ignored issues
show
Duplication introduced by
This class 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...
16
{
17
18
    /**
19
     * @var  \App\Containers\Authorization\Tasks\SyncPermissionsOnRoleTask
20
     */
21
    private $syncPermissionsOnRoleTask;
22
23
    /**
24
     * @var  \App\Containers\Authorization\Tasks\GetRoleTask
25
     */
26
    private $getRoleTask;
27
28
    /**
29
     * @var  \App\Containers\Authorization\Tasks\GetPermissionTask
30
     */
31
    private $getPermissionTask;
32
33
    /**
34
     * AttachPermissionsToRoleAction constructor.
35
     *
36
     * @param \App\Containers\Authorization\Tasks\SyncPermissionsOnRoleTask $syncPermissionsOnRoleTask
37
     * @param \App\Containers\Authorization\Tasks\GetRoleTask                 $getRoleTask
38
     */
39
    public function __construct(
40
        SyncPermissionsOnRoleTask $syncPermissionsOnRoleTask,
41
        GetRoleTask $getRoleTask,
42
        GetPermissionTask $getPermissionTask
43
    ) {
44
        $this->syncPermissionsOnRoleTask = $syncPermissionsOnRoleTask;
45
        $this->getRoleTask = $getRoleTask;
46
        $this->getPermissionTask = $getPermissionTask;
47
    }
48
49
    /**
50
     * @param $roleId
51
     * @param $permissionsIds
52
     *
53
     * @return  \App\Containers\Authorization\Models\Role
54
     */
55
    public function run($roleId, $permissionsIds)
56
    {
57
        $role = $this->getRoleTask->run($roleId);
58
59
        $permissions = [];
60
61
        if (is_array($permissionsIds)) {
62
            foreach ($permissionsIds as $permissionId){
63
                $permissions[] = $this->getPermissionTask->run($permissionId);
64
            }
65
        }else{
66
            $permissions[] = $this->getPermissionTask->run($permissionsIds);
67
        }
68
69
        return $this->syncPermissionsOnRoleTask->run($role, $permissions);
70
    }
71
}
72