Add the Comment class

This commit is contained in:
Oliver Davies 2019-02-14 07:52:16 +00:00
parent df9639e57c
commit 4292cc3147
3 changed files with 61 additions and 2 deletions

52
src/Comment.php Normal file
View file

@ -0,0 +1,52 @@
<?php
namespace App;
class Comment
{
/**
* @var string
*/
private $text;
/**
* @var string
*/
private $userDisplayName;
/**
* Set the comment text.
*
* @param string $text
*/
public function setText(string $text)
{
$this->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;
}
}

View file

@ -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;

View file

@ -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 */