RoleTransformer   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 39
Duplicated Lines 28.21 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 2
dl 11
loc 39
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A transform() 11 11 1
A includePermissions() 0 4 1

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\UI\API\Transformers;
4
5
use App\Containers\Authorization\Models\Role;
6
use App\Ship\Parents\Transformers\Transformer;
7
8
/**
9
 * Class RoleTransformer.
10
 *
11
 * @author Mahmoud Zalt <[email protected]>
12
 */
13
class RoleTransformer extends Transformer
14
{
15
16
    protected $availableIncludes = [
17
18
    ];
19
20
    protected $defaultIncludes = [
21
        'permissions'
22
    ];
23
24
    /**
25
     * @param \App\Containers\Authorization\Models\Role $role
26
     *
27
     * @return array
28
     */
29 View Code Duplication
    public function transform(Role $role)
0 ignored issues
show
Duplication introduced by Mahmoud Zalt
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...
30
    {
31
        return [
32
            'object'       => 'Role',
33
            'id'           => $role->getHashedKey(), // << Unique Identifier
34
            'name'         => $role->name, // << Unique Identifier
35
            'description'  => $role->description,
36
            'display_name' => $role->display_name,
37
            'level'        => $role->level,
38
        ];
39
    }
40
41
    /**
42
     * @param \App\Containers\Authorization\Models\Role $role
43
     *
44
     * @return  \League\Fractal\Resource\Collection
45
     */
46
    public function includePermissions(Role $role)
47
    {
48
        return $this->collection($role->permissions, new PermissionTransformer());
49
    }
50
51
}
52