Code Duplication    Length = 57-57 lines in 2 locations

app/Containers/Authorization/Actions/AttachPermissionsToRoleAction.php 1 location

@@ 15-71 (lines=57) @@
12
 *
13
 * @author Mahmoud Zalt <[email protected]>
14
 */
15
class AttachPermissionsToRoleAction extends Action
16
{
17
18
    /**
19
     * @var  \App\Containers\Authorization\Tasks\AttachPermissionsToRoleTask
20
     */
21
    private $attachPermissionsToRoleTask;
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\AttachPermissionsToRoleTask $attachPermissionsToRoleTask
37
     * @param \App\Containers\Authorization\Tasks\GetRoleTask                 $getRoleTask
38
     */
39
    public function __construct(
40
        AttachPermissionsToRoleTask $attachPermissionsToRoleTask,
41
        GetRoleTask $getRoleTask,
42
        GetPermissionTask $getPermissionTask
43
    ) {
44
        $this->attachPermissionsToRoleTask = $attachPermissionsToRoleTask;
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->attachPermissionsToRoleTask->run($role, $permissions);
70
    }
71
}
72

app/Containers/Authorization/Actions/SyncPermissionsOnRoleAction.php 1 location

@@ 15-71 (lines=57) @@
12
 *
13
 * @author Mahmoud Zalt <[email protected]>
14
 */
15
class SyncPermissionsOnRoleAction extends Action
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