Code Duplication    Length = 24-24 lines in 3 locations

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

@@ 15-38 (lines=24) @@
12
 *
13
 * @author Mahmoud Zalt <[email protected]>
14
 */
15
class AttachPermissionsToRoleAction extends Action
16
{
17
18
    /**
19
     * @param \App\Ship\Transporters\DataTransporter $data
20
     *
21
     * @return  \App\Containers\Authorization\Models\Role
22
     */
23
    public function run(DataTransporter $data): Role
24
    {
25
        $role = Apiato::call('[email protected]', [$data->role_id]);
26
27
        // convert to array in case single ID was passed
28
        $permissionIds = (array)$data->permissions_ids;
29
30
        $permissions = array_map(function ($permissionId) {
31
            return Apiato::call('[email protected]', [$permissionId]);
32
        }, $permissionIds);
33
34
        $role = $role->givePermissionTo($permissions);
35
36
        return $role;
37
    }
38
}
39

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

@@ 15-38 (lines=24) @@
12
 *
13
 * @author Mahmoud Zalt <[email protected]>
14
 */
15
class SyncPermissionsOnRoleAction extends Action
16
{
17
18
    /**
19
     * @param \App\Ship\Transporters\DataTransporter $data
20
     *
21
     * @return  \App\Containers\Authorization\Models\Role
22
     */
23
    public function run(DataTransporter $data): Role
24
    {
25
        $role = Apiato::call('[email protected]', [$data->role_id]);
26
27
        // convert to array in case single ID was passed
28
        $permissionsIds = (array)$data->permissions_ids;
29
30
        $permissions = array_map(function ($permissionId) {
31
            return Apiato::call('[email protected]', [$permissionId]);
32
        }, $permissionsIds);
33
34
        $role->syncPermissions($permissions);
35
36
        return $role;
37
    }
38
}
39

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

@@ 15-38 (lines=24) @@
12
 *
13
 * @author Mahmoud Zalt <[email protected]>
14
 */
15
class SyncUserRolesAction extends Action
16
{
17
18
    /**
19
     * @param \App\Ship\Transporters\DataTransporter $data
20
     *
21
     * @return  \App\Containers\User\Models\User
22
     */
23
    public function run(DataTransporter $data): User
24
    {
25
        $user = Apiato::call('[email protected]', [$data->user_id]);
26
27
        // convert roles IDs to array (in case single id passed)
28
        $rolesIds = (array)$data->roles_ids;
29
30
        $roles = array_map(function ($roleId) {
31
            return Apiato::call('[email protected]', [$roleId]);
32
        }, $rolesIds);
33
34
        $user->syncRoles($roles);
35
36
        return $user;
37
    }
38
}
39