From 4292cc3147a10825bae31d3c074c54ab3fc47031 Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Thu, 14 Feb 2019 07:52:16 +0000 Subject: [PATCH] Add the Comment class --- src/Comment.php | 52 ++++++++++++++++++++++++++++++++++++ src/Service/Picker.php | 7 +++++ tests/Service/PickerTest.php | 4 +-- 3 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 src/Comment.php diff --git a/src/Comment.php b/src/Comment.php new file mode 100644 index 0000000..761614e --- /dev/null +++ b/src/Comment.php @@ -0,0 +1,52 @@ +text = $text; + } + + /** + * Set the user's display name. + * + * @param string $name + */ + public function setUserDisplayName(string $name) + { + $this->userDisplayName = $name; + } + + /** + * @return string + */ + public function getText(): string + { + return $this->text; + } + + /** + * @return mixed + */ + public function getUserDisplayName(): string + { + return $this->userDisplayName; + } +} diff --git a/src/Service/Picker.php b/src/Service/Picker.php index b886911..1b7e839 100644 --- a/src/Service/Picker.php +++ b/src/Service/Picker.php @@ -2,6 +2,7 @@ namespace App\Service; +use App\Comment; use Tightenco\Collect\Support\Collection; class Picker @@ -80,6 +81,12 @@ class Picker ->filter(function (\stdClass $comment) { return !$this->isUserAnEventHost($comment->user_display_name); }) + ->map(function (\stdClass $original) { + return tap(new Comment(), function (Comment $comment) use ($original) { + $comment->setText($original->comment); + $comment->setUserDisplayName($original->user_display_name); + }); + }) ->values(); return $this; diff --git a/tests/Service/PickerTest.php b/tests/Service/PickerTest.php index 630509e..0870676 100644 --- a/tests/Service/PickerTest.php +++ b/tests/Service/PickerTest.php @@ -96,8 +96,8 @@ class PickerTest extends TestCase ->getComments(); $this->assertCount(2, $comments); - $this->assertSame('Peter Fisher', $comments[0]->user_display_name); - $this->assertSame('Zan Baldwin', $comments[1]->user_display_name); + $this->assertSame('Peter Fisher', $comments[0]->getUserDisplayName()); + $this->assertSame('Zan Baldwin', $comments[1]->getUserDisplayName()); } /** @test */