Skip to content

Commit

Permalink
data transformer and thread entity fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
zocimek committed Aug 21, 2012
1 parent d747579 commit 01bf25f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
14 changes: 7 additions & 7 deletions DataTransformer/RecipientsDataTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ public function __construct(UserToUsernameTransformer $userToUsernameTransformer
/**
* Transforms a collection of recipients into a string
*
* @param Collection|null $recipients
* @param Collection $recipients
*
* @return string
*/
public function transform($recipients)
{
if (null === $recipients || $recipients->count() == 0) {
if ($recipients->count() == 0) {
return "";
}

Expand All @@ -55,7 +55,7 @@ public function transform($recipients)
*
* @param string $usernames
*
* @return array|null
* @param Collection $recipients
*/
public function reverseTransform($usernames)
{
Expand All @@ -67,18 +67,18 @@ public function reverseTransform($usernames)
throw new UnexpectedTypeException($usernames, 'string');
}

$recipients = array();
$recipients = new ArrayCollection();
$transformer = $this->userToUsernameTransformer;
$recipientsNames = array_filter(explode(', ', $usernames));
$recipientsNames = array_filter(explode(',', $usernames));

foreach ($recipientsNames as $username) {
$user = $this->userToUsernameTransformer->reverseTransform($username);
$user = $this->userToUsernameTransformer->reverseTransform(trim($username));

if (!$user instanceof \Symfony\Component\Security\Core\User\UserInterface) {
throw new TransformationFailedException(sprintf('User "%s" does not exists', $username));
}

$recipients[] = $user;
$recipients->add($user);
}

return $recipients;
Expand Down
7 changes: 4 additions & 3 deletions Entity/Thread.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,15 @@ public function addParticipant(ParticipantInterface $participant)
/**
* Adds many participants to the thread
*
* @param array|Collection
* @param array|\Traversable
*
* @throws \InvalidArgumentException
* @return Thread
*/
public function addParticipants($participants)
{
if (!is_array($participants) && !$participants instanceof Collection) {
throw new \InvalidArgumentException("Participants must array or instanceof Collection");
if (!is_array($participants) && !$participants instanceof \Traversable) {
throw new \InvalidArgumentException("Participants must array or instanceof Traversable");
}

foreach ($participants as $participant) {
Expand Down

0 comments on commit 01bf25f

Please sign in to comment.