Created
July 29, 2016 07:30
-
-
Save davidpiesse/f2f7fbabb3c7e1a6c6751faac76f83fe to your computer and use it in GitHub Desktop.
A refactoring challenge for Adam Wathan at Laracon 2016
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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