Completed
Push — master ( 211dc8...3ba04c )
by Mahmoud
03:02
created

UserTransformer   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 3
c 0
b 0
f 0
lcom 0
cbo 3
dl 0
loc 49
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
B transform() 0 31 2
A includeRoles() 0 4 1
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\Port\Transformer\Abstracts\Transformer;
8
9
/**
10
 * Class UserTransformer.
11
 *
12
 * @author Mahmoud Zalt <[email protected]>
13
 */
14
class UserTransformer extends Transformer
15
{
16
17
    protected $defaultIncludes = [
18
        'roles',
19
    ];
20
21
    /**
22
     * @param \App\Containers\User\Models\User $user
23
     *
24
     * @return array
25
     */
26
    public function transform(User $user)
27
    {
28
29
        return [
30
            'id'                   => (int)$user->getHashedKey(),
31
            'name'                 => $user->name,
32
            'email'                => $user->email,
33
            'confirmed'            => $user->confirmed,
34
            'nickname'             => $user->nickname,
35
            'gender'               => $user->gender,
36
            'birth'                => $user->birth,
37
            'visitor_id'           => $user->visitor_id,
38
            'social_auth_provider' => $user->social_provider,
39
            'social_id'            => $user->social_id,
40
            'social_avatar'        => [
41
                'avatar'   => $user->social_avatar,
42
                'original' => $user->social_avatar_original,
43
            ],
44
            'created_at'           => $user->created_at,
45
            'token'                => $user->token,
46
        ];
47
48
        if ($this->isUserAdmin()) {
0 ignored issues
show
Unused Code introduced by
if ($this->isUserAdmin()... $user->deleted_at)); } does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
49
            $response = array_merge($response, [
50
                'updated_at' => $user->updated_at,
51
                'deleted_at' => $user->deleted_at,
52
            ]);
53
        }
54
55
        return $response;
56
    }
57
58
    public function includeRoles(User $user)
59
    {
60
        return $this->collection($user->roles, new RoleTransformer());
61
    }
62
}
63