Add the Comment class
This commit is contained in:
parent
df9639e57c
commit
4292cc3147
52
src/Comment.php
Normal file
52
src/Comment.php
Normal 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;
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
|
|
|
@ -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 */
|
||||
|
|
Loading…
Reference in a new issue