Skip to content

Commit

Permalink
Refactoring message type
Browse files Browse the repository at this point in the history
  • Loading branch information
iGusev committed Jun 29, 2015
1 parent 8150deb commit d3aa199
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions src/Types/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -570,26 +570,34 @@ public static function fromResponse($data)
}

if (isset($data['new_chat_photo'])) {
$newChatPhoto = array();
foreach ($data['new_chat_photo'] as $newChatPhotoItem) {
$newChatPhoto[] = PhotoSize::fromResponse($newChatPhotoItem);
}
$instance->setNewChatPhoto($newChatPhoto);
$instance->setNewChatPhoto(self::generateArrayOfPhotoSize($data['new_chat_photo']));
}

if (isset($data['photo'])) {
$photo = array();
foreach ($data['photo'] as $photoItem) {
$photo[] = PhotoSize::fromResponse($photoItem);
}
$instance->setPhoto($photo);
$instance->setPhoto(self::generateArrayOfPhotoSize($data['photo']));
}


if (isset($data['group_chat_created'])) {
$instance->setGroupChatCreated($data['group_chat_created']);
}

return $instance;
}

/**
* Returns array of PhotoSize from raw
*
* @param $data
*
* @return array
*/
protected static function generateArrayOfPhotoSize($data)
{
$arrayOfPhotoSize = array();
foreach ($data as $photoSizeItem) {
$arrayOfPhotoSize[] = PhotoSize::fromResponse($photoSizeItem);
}

return $arrayOfPhotoSize;
}
}

0 comments on commit d3aa199

Please sign in to comment.