UserPrivateProfileTransformer   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 61
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A transform() 32 32 1
A includeRoles() 4 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\User\UI\API\Transformers;
4
5
use App\Containers\Authorization\UI\API\Transformers\RoleTransformer;
6
use App\Containers\User\Models\User;
7
use App\Ship\Parents\Transformers\Transformer;
8
9
/**
10
 * Class UserPrivateProfileTransformer.
11
 *
12
 * @author Johannes Schobel <[email protected]>
13
 */
14 View Code Duplication
class UserPrivateProfileTransformer extends Transformer
0 ignored issues
show
Duplication introduced by Mahmoud Zalt
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...
15
{
16
17
    /**
18
     * @var  array
19
     */
20
    protected $availableIncludes = [
21
        'roles',
22
    ];
23
24
    /**
25
     * @var  array
26
     */
27
    protected $defaultIncludes = [
28
29
    ];
30
31
    /**
32
     * @param \App\Containers\User\Models\User $user
33
     *
34
     * @return array
35
     */
36
    public function transform(User $user)
37
    {
38
        $response = [
39
            'object'               => 'User',
40
            'id'                   => $user->getHashedKey(),
41
            'name'                 => $user->name,
42
            'email'                => $user->email,
43
            'confirmed'            => $user->confirmed,
44
            'nickname'             => $user->nickname,
45
            'gender'               => $user->gender,
46
            'birth'                => $user->birth,
47
48
            'social_auth_provider' => $user->social_provider,
49
            'social_id'            => $user->social_id,
50
            'social_avatar'        => [
51
                'avatar'   => $user->social_avatar,
52
                'original' => $user->social_avatar_original,
53
            ],
54
55
            'created_at'           => $user->created_at,
56
            'updated_at'           => $user->updated_at,
57
            'readable_created_at'  => $user->created_at->diffForHumans(),
58
            'readable_updated_at'  => $user->updated_at->diffForHumans(),
59
        ];
60
61
        $response = $this->ifAdmin([
62
            'real_id'    => $user->id,
63
            'deleted_at' => $user->deleted_at,
64
        ], $response);
65
66
        return $response;
67
    }
68
69
    public function includeRoles(User $user)
70
    {
71
        return $this->collection($user->roles, new RoleTransformer());
72
    }
73
74
}
75