Conditions | 6 |
Paths | 7 |
Total Lines | 57 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
32 | public function __construct(\stdClass $response) |
||
33 | { |
||
34 | if (isset($response->guild->error)) { |
||
35 | throw new NotFoundException('Guild does not exists.'); |
||
36 | } |
||
37 | |||
38 | $invitees = collect(); |
||
39 | foreach ($response->guild->invited as $invitee) { |
||
40 | $invitees->push(new Invitee($invitee->name, new Carbon($invitee->invited))); |
||
41 | } |
||
42 | $invited = new Invited($invitees); |
||
43 | |||
44 | $members = collect(); |
||
45 | $characters = collect(); |
||
46 | foreach ($response->guild->members as $members_data) { |
||
47 | foreach ($members_data->characters as $character) { |
||
48 | $characters->push(new Character( |
||
49 | $character->name, |
||
50 | $character->nick, |
||
51 | $character->level, |
||
52 | $character->vocation, |
||
53 | new Carbon($character->joined), |
||
54 | $character->status |
||
55 | )); |
||
56 | } |
||
57 | |||
58 | $members->push(new Members($members_data->rank_title, $characters)); |
||
59 | } |
||
60 | |||
61 | $this->guild = Guild::createFromArray([ |
||
62 | 'name' => $response->guild->data->name, |
||
63 | 'description' => $response->guild->data->description, |
||
64 | 'guildhall' => $response->guild->data->guildhall ? new Guildhall( |
||
65 | $response->guild->data->guildhall->name, |
||
66 | $response->guild->data->guildhall->town, |
||
67 | new Carbon($response->guild->data->guildhall->paid), |
||
68 | $response->guild->data->guildhall->world, |
||
69 | $response->guild->data->guildhall->houseid |
||
70 | ) : null, |
||
71 | 'application' => $response->guild->data->application, |
||
72 | 'war' => $response->guild->data->war, |
||
73 | 'online_status' => $response->guild->data->online_status, |
||
74 | 'offline_status' => $response->guild->data->offline_status, |
||
75 | 'disbanded' => $response->guild->data->disbanded, |
||
76 | 'totalmembers' => $response->guild->data->totalmembers, |
||
77 | 'totalinvited' => $response->guild->data->totalinvited, |
||
78 | 'world' => $response->guild->data->world, |
||
79 | 'founded' => new Carbon($response->guild->data->founded), |
||
80 | 'active' => $response->guild->data->active ?? null, |
||
81 | 'homepage' => $response->guild->data->homepage ?? '', |
||
82 | 'guildlogo' => $response->guild->data->guildlogo, |
||
83 | 'members' => $members, |
||
84 | 'invited' => $invited, |
||
85 | ]); |
||
86 | |||
87 | parent::__construct($response); |
||
88 | } |
||
89 | |||
98 |