Passed
Push — master ( ef2d88...898186 )
by Arthur
06:43
created

UserTransformer   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 36
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A transformRoles() 0 3 1
A transformPermissions() 0 3 1
A toArray() 0 11 1
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: arthur
5
 * Date: 29.10.18
6
 * Time: 12:06
7
 */
8
9
namespace Modules\User\Transformers;
10
11
use Foundation\Abstracts\Transformers\Transformer;
12
use Modules\Authorization\Resources\PermissionResource;
13
use Modules\Authorization\Resources\RoleResource;
14
use Modules\User\Entities\User;
15
16
class UserTransformer extends Transformer
17
{
18
    public $relations = [
19
        'roles',
20
        'permissions'
21
    ];
22
23
    /**
24
     * Transform the resource into an array.
25
     *
26
     * @param \Illuminate\Http\Request $request
27
     *
28
     * @return array
29
     */
30
    public function toArray($request)
31
    {
32
        return [
33
            'id' => $this->id,
0 ignored issues
show
Bug Best Practice introduced by
The property id does not exist on Modules\User\Transformers\UserTransformer. Since you implemented __get, consider adding a @property annotation.
Loading history...
34
            'name' => $this->name,
0 ignored issues
show
Bug Best Practice introduced by
The property name does not exist on Modules\User\Transformers\UserTransformer. Since you implemented __get, consider adding a @property annotation.
Loading history...
35
            'email' => $this->name,
36
            'email_verified' => $this->email_verified,
0 ignored issues
show
Bug Best Practice introduced by
The property email_verified does not exist on Modules\User\Transformers\UserTransformer. Since you implemented __get, consider adding a @property annotation.
Loading history...
37
            'gender' => $this->gender,
0 ignored issues
show
Bug Best Practice introduced by
The property gender does not exist on Modules\User\Transformers\UserTransformer. Since you implemented __get, consider adding a @property annotation.
Loading history...
38
            'provider' => $this->provider,
0 ignored issues
show
Bug Best Practice introduced by
The property provider does not exist on Modules\User\Transformers\UserTransformer. Since you implemented __get, consider adding a @property annotation.
Loading history...
39
            'created_at' => $this->created_at,
0 ignored issues
show
Bug Best Practice introduced by
The property created_at does not exist on Modules\User\Transformers\UserTransformer. Since you implemented __get, consider adding a @property annotation.
Loading history...
40
            'updated_at' => $this->updated_at,
0 ignored issues
show
Bug Best Practice introduced by
The property updated_at does not exist on Modules\User\Transformers\UserTransformer. Since you implemented __get, consider adding a @property annotation.
Loading history...
41
        ];
42
    }
43
44
    public function transformRoles(User $user)
45
    {
46
        return collect(RoleResource::collection($user->roles))->flatten();
0 ignored issues
show
Bug introduced by
The property roles does not exist on Modules\User\Entities\User. Did you mean roleClass?
Loading history...
47
    }
48
49
    public function transformPermissions(User $user)
50
    {
51
        return collect(PermissionResource::collection($user->getAllPermissions())->toArray(null))->flatten();
52
    }
53
}
54