Skip to content

Instantly share code, notes, and snippets.

@davidpiesse
Created July 29, 2016 07:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidpiesse/f2f7fbabb3c7e1a6c6751faac76f83fe to your computer and use it in GitHub Desktop.
Save davidpiesse/f2f7fbabb3c7e1a6c6751faac76f83fe to your computer and use it in GitHub Desktop.
A refactoring challenge for Adam Wathan at Laracon 2016
//this function returns entrymessage objects only if the entrymessage is a mesaage, and the internal message object isText.
//From Facebook messenger api
//Got parts refractories but couldn't work out how to return a collection of valid entrymessages with the double foreach.
//Tried lots of combos of each/map/ and filter.
public function textMessages()
{
$result = [];
foreach ($this->entries as $entry) {
foreach ($entry->messages as $entryMessage) {
if ($entryMessage->isMessage) {
if ($entryMessage->message->isText)
$result[] = $entryMessage;
}
}
}
return collect($result);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment