Passed
Push — master ( c13b73...f2713c )
by Arthur
05:06
created

AccountTransformer   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 28
dl 0
loc 57
rs 10
c 0
b 0
f 0
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A toArray() 0 8 2
A transformUser() 0 3 1
A OSRSAccountToArray() 0 15 1
A transformMachine() 0 3 1
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: arthur
5
 * Date: 29.10.18
6
 * Time: 09:38.
7
 */
8
9
namespace Modules\Account\Transformers;
10
11
use Foundation\Abstracts\Transformers\Transformer;
12
use Foundation\Exceptions\Exception;
13
use Modules\Account\Entities\Account;
14
use Modules\Machine\Transformers\MachineTransformer;
15
use Modules\User\Transformers\UserTransformer;
16
17
class AccountTransformer extends Transformer
18
{
19
    public $available = [
20
        'user',
21
        'machine'
22
    ];
23
24
    public $include = [
25
        'machine',
26
        'user'
27
    ];
28
29
    /**
30
     * Transform the resource into an array.
31
     *
32
     * @param \Illuminate\Http\Request $request
33
     *
34
     * @return array
35
     * @throws Exception
36
     */
37
    public function toArray($request)
38
    {
39
        $game = $this->game ?? null;
0 ignored issues
show
Bug Best Practice introduced by
The property game does not exist on Modules\Account\Transformers\AccountTransformer. Since you implemented __get, consider adding a @property annotation.
Loading history...
40
        switch ($game) {
41
            case "OSRS":
42
                return $this->OSRSAccountToArray();
43
            default:
44
                throw new Exception("Could not identity account game type");
45
        }
46
    }
47
48
    protected function OSRSAccountToArray()
49
    {
50
        return [
51
            'id' => $this->id,
0 ignored issues
show
Bug Best Practice introduced by
The property id does not exist on Modules\Account\Transformers\AccountTransformer. Since you implemented __get, consider adding a @property annotation.
Loading history...
52
            'username' => $this->username,
0 ignored issues
show
Bug Best Practice introduced by
The property username does not exist on Modules\Account\Transformers\AccountTransformer. Since you implemented __get, consider adding a @property annotation.
Loading history...
53
            'password' => $this->password,
0 ignored issues
show
Bug Best Practice introduced by
The property password does not exist on Modules\Account\Transformers\AccountTransformer. Since you implemented __get, consider adding a @property annotation.
Loading history...
54
            'game' => $this->game,
0 ignored issues
show
Bug Best Practice introduced by
The property game does not exist on Modules\Account\Transformers\AccountTransformer. Since you implemented __get, consider adding a @property annotation.
Loading history...
55
            "bank_pin" => $this->bank_pin,
0 ignored issues
show
Bug Best Practice introduced by
The property bank_pin does not exist on Modules\Account\Transformers\AccountTransformer. Since you implemented __get, consider adding a @property annotation.
Loading history...
56
            "location" => $this->location,
0 ignored issues
show
Bug Best Practice introduced by
The property location does not exist on Modules\Account\Transformers\AccountTransformer. Since you implemented __get, consider adding a @property annotation.
Loading history...
57
            "ingame_name" => $this->ingame_name,
0 ignored issues
show
Bug Best Practice introduced by
The property ingame_name does not exist on Modules\Account\Transformers\AccountTransformer. Since you implemented __get, consider adding a @property annotation.
Loading history...
58
            "skills" => $this->skills,
0 ignored issues
show
Bug Best Practice introduced by
The property skills does not exist on Modules\Account\Transformers\AccountTransformer. Since you implemented __get, consider adding a @property annotation.
Loading history...
59
            "membership_expires_at" => $this->membership_expires_at,
0 ignored issues
show
Bug Best Practice introduced by
The property membership_expires_at does not exist on Modules\Account\Transformers\AccountTransformer. Since you implemented __get, consider adding a @property annotation.
Loading history...
60
            'banned_at' => $this->banned_at,
0 ignored issues
show
Bug Best Practice introduced by
The property banned_at does not exist on Modules\Account\Transformers\AccountTransformer. Since you implemented __get, consider adding a @property annotation.
Loading history...
61
            'created_at' => $this->created_at,
0 ignored issues
show
Bug Best Practice introduced by
The property created_at does not exist on Modules\Account\Transformers\AccountTransformer. Since you implemented __get, consider adding a @property annotation.
Loading history...
62
            'updated_at' => $this->updated_at,
0 ignored issues
show
Bug Best Practice introduced by
The property updated_at does not exist on Modules\Account\Transformers\AccountTransformer. Since you implemented __get, consider adding a @property annotation.
Loading history...
63
        ];
64
    }
65
66
    public function transformUser(Account $account)
67
    {
68
        return UserTransformer::resource($account->user);
69
    }
70
71
    public function transformMachine(Account $account)
72
    {
73
        return MachineTransformer::resource($account->machine);
74
    }
75
}
76