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

SyncPermissionsOnRoleAction   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 57
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 4
c 0
b 0
f 0
lcom 1
cbo 4
dl 57
loc 57
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 9 9 1
A run() 16 16 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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