Skip to content

Commit

Permalink
Fix #287 and improve CS/readability of various parts of the code
Browse files Browse the repository at this point in the history
  • Loading branch information
tgalopin committed Sep 3, 2016
1 parent d33c18a commit f63498c
Show file tree
Hide file tree
Showing 69 changed files with 243 additions and 567 deletions.
22 changes: 8 additions & 14 deletions Command/MongoDBMigrateMetadataCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class MongoDBMigrateMetadataCommand extends ContainerAwareCommand
private $printStatusCallback;

/**
* @see Symfony\Component\Console\Command\Command::isEnabled()
* {@inheritdoc}
*/
public function isEnabled()
{
Expand All @@ -49,7 +49,7 @@ public function isEnabled()
}

/**
* @see Symfony\Component\Console\Command\Command::configure()
* {@inheritdoc}
*/
protected function configure()
{
Expand Down Expand Up @@ -92,7 +92,7 @@ protected function configure()
}

/**
* @see Symfony\Bundle\FrameworkBundle\Command\Command::initialize()
* {@inheritdoc}
*/
protected function initialize(InputInterface $input, OutputInterface $output)
{
Expand All @@ -113,7 +113,7 @@ protected function initialize(InputInterface $input, OutputInterface $output)
}

/**
* @see Symfony\Component\Console\Command\Command::execute()
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
Expand All @@ -122,13 +122,11 @@ protected function execute(InputInterface $input, OutputInterface $output)

$size = memory_get_peak_usage(true);
$unit = array('b', 'k', 'm', 'g', 't', 'p');
$output->writeln(sprintf("Peak Memory Usage: <comment>%s</comment>", round($size / pow(1024, ($i = floor(log($size, 1024)))), 2).$unit[$i]));
$output->writeln(sprintf('Peak Memory Usage: <comment>%s</comment>', round($size / pow(1024, $i = floor(log($size, 1024))), 2).$unit[$i]));
}

/**
* Migrate message documents
*
* @param OutputInterface $output
*/
private function migrateMessages(OutputInterface $output)
{
Expand Down Expand Up @@ -175,8 +173,6 @@ private function migrateMessages(OutputInterface $output)

/**
* Migrate thread documents
*
* @param OutputInterface $output
*/
private function migrateThreads(OutputInterface $output)
{
Expand Down Expand Up @@ -233,8 +229,6 @@ private function migrateThreads(OutputInterface $output)
*
* By default, Mongo will not include "$db" when creating the participant
* reference. We'll add that manually to be consistent with Doctrine.
*
* @param array &$message
*/
private function createMessageMetadata(array &$message)
{
Expand All @@ -253,7 +247,7 @@ private function createMessageMetadata(array &$message)
/**
* Sets the unreadForParticipants array on the message.
*
* @see FOS\MessageBundle\Document\Message::doEnsureUnreadForParticipantsArray()
* @see \FOS\MessageBundle\Document\Message::doEnsureUnreadForParticipantsArray()
* @param array &$message
*/
private function createMessageUnreadForParticipants(array &$message)
Expand Down Expand Up @@ -331,7 +325,7 @@ private function createThreadLastMessageDate(array &$thread)
/**
* Sets the active participant arrays on the thread.
*
* @see FOS\MessageBundle\Document\Thread::doEnsureActiveParticipantArrays()
* @see \FOS\MessageBundle\Document\Thread::doEnsureActiveParticipantArrays()
* @param array $thread
*/
private function createThreadActiveParticipantArrays(array &$thread)
Expand All @@ -342,7 +336,7 @@ private function createThreadActiveParticipantArrays(array &$thread)

foreach ($thread['participants'] as $participantRef) {
foreach ($thread['metadata'] as $metadata) {
if ($participantRef['$id'] == $metadata['participant']['$id'] && $metadata['isDeleted']) {
if ($metadata['isDeleted'] && $participantRef['$id'] === $metadata['participant']['$id']) {
continue 2;
}
}
Expand Down
9 changes: 5 additions & 4 deletions Composer/ComposerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace FOS\MessageBundle\Composer;

use FOS\MessageBundle\MessageBuilder\AbstractMessageBuilder;
use FOS\MessageBundle\Model\ThreadInterface;

/**
Expand All @@ -14,14 +15,14 @@ interface ComposerInterface
/**
* Starts composing a message, starting a new thread
*
* @return MessageBuilderInterface
* @return AbstractMessageBuilder
*/
function newThread();
public function newThread();

/**
* Starts composing a message in a reply to a thread
*
* @return MessageBuilderInterface
* @return AbstractMessageBuilder
*/
function reply(ThreadInterface $thread);
public function reply(ThreadInterface $thread);
}
2 changes: 1 addition & 1 deletion Controller/MessageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

namespace FOS\MessageBundle\Controller;

use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\DependencyInjection\ContainerAware;
use Symfony\Component\HttpFoundation\RedirectResponse;
use FOS\MessageBundle\Provider\ProviderInterface;
use Symfony\Component\HttpFoundation\Response;

class MessageController extends ContainerAware
{
Expand Down
10 changes: 3 additions & 7 deletions DataTransformer/RecipientsDataTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use Symfony\Component\Form\Exception\TransformationFailedException;
use Symfony\Component\Form\Exception\UnexpectedTypeException;
use Symfony\Component\Security\Core\User\UserInterface;
use Doctrine\Common\Persistence\ObjectManager;
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\ArrayCollection;
/**
Expand All @@ -20,9 +19,6 @@ class RecipientsDataTransformer implements DataTransformerInterface
*/
private $userToUsernameTransformer;

/**
* @param DataTransformerInterface $userToUsernameTransformer
*/
public function __construct(DataTransformerInterface $userToUsernameTransformer)
{
$this->userToUsernameTransformer = $userToUsernameTransformer;
Expand All @@ -37,8 +33,8 @@ public function __construct(DataTransformerInterface $userToUsernameTransformer)
*/
public function transform($recipients)
{
if ($recipients === null || $recipients->count() == 0) {
return "";
if ($recipients === null || $recipients->count() === 0) {
return '';
}

$usernames = array();
Expand Down Expand Up @@ -84,4 +80,4 @@ public function reverseTransform($usernames)

return $recipients;
}
}
}
9 changes: 3 additions & 6 deletions Deleter/Deleter.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace FOS\MessageBundle\Deleter;

use FOS\MessageBundle\Model\ParticipantInterface;
use FOS\MessageBundle\Security\AuthorizerInterface;
use FOS\MessageBundle\Model\ThreadInterface;
use FOS\MessageBundle\Security\ParticipantProviderInterface;
Expand Down Expand Up @@ -46,9 +47,7 @@ public function __construct(AuthorizerInterface $authorizer, ParticipantProvider
}

/**
* Marks the thread as deleted by the current authenticated user
*
* @param ThreadInterface $thread
* {@inheritdoc}
*/
public function markAsDeleted(ThreadInterface $thread)
{
Expand All @@ -61,9 +60,7 @@ public function markAsDeleted(ThreadInterface $thread)
}

/**
* Marks the thread as undeleted by the current authenticated user
*
* @param ThreadInterface $thread
* {@inheritdoc}
*/
public function markAsUndeleted(ThreadInterface $thread)
{
Expand Down
8 changes: 2 additions & 6 deletions Deleter/DeleterInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,11 @@ interface DeleterInterface
{
/**
* Marks the thread as deleted by the current authenticated user
*
* @param ThreadInterface $thread
*/
function markAsDeleted(ThreadInterface $thread);
public function markAsDeleted(ThreadInterface $thread);

/**
* Marks the thread as undeleted by the current authenticated user
*
* @param ThreadInterface $thread
*/
function markAsUndeleted(ThreadInterface $thread);
public function markAsUndeleted(ThreadInterface $thread);
}
1 change: 0 additions & 1 deletion DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace FOS\MessageBundle\DependencyInjection;

use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Symfony\Component\Config\Definition\ConfigurationInterface;

/**
Expand Down
5 changes: 2 additions & 3 deletions Document/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,14 @@ abstract class Message extends BaseMessage
protected $unreadForParticipants = array();

/**
* @param boolean
* @return null
* @param boolean $isSpam
*/
public function setIsSpam($isSpam)
{
$this->isSpam = (boolean) $isSpam;
}

/**
/*
* DENORMALIZATION
*
* All following methods are relative to denormalization
Expand Down
9 changes: 3 additions & 6 deletions Document/Thread.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
namespace FOS\MessageBundle\Document;

use FOS\MessageBundle\Model\Thread as AbstractThread;
use FOS\MessageBundle\Model\MessageInterface;
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\ArrayCollection;
use FOS\MessageBundle\Model\ParticipantInterface;

abstract class Thread extends AbstractThread
Expand All @@ -16,7 +13,7 @@ abstract class Thread extends AbstractThread
* This denormalization field is used for sorting threads in the inbox and
* sent list.
*
* @var DateTime
* @var \DateTime
*/
protected $lastMessageDate;

Expand Down Expand Up @@ -69,7 +66,7 @@ public function getParticipants()
* If it already exists, nothing is done.
*
* @param ParticipantInterface $participant
* @return null
* @return void
*/
public function addParticipant(ParticipantInterface $participant)
{
Expand All @@ -89,7 +86,7 @@ public function isParticipant(ParticipantInterface $participant)
return $this->participants->contains($participant);
}

/**
/*
* DENORMALIZATION
*
* All following methods are relative to denormalization
Expand Down
37 changes: 9 additions & 28 deletions DocumentManager/MessageManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Doctrine\ODM\MongoDB\DocumentManager;
use FOS\MessageBundle\Document\Message;
use FOS\MessageBundle\Document\MessageMetadata;
use FOS\MessageBundle\Model\MessageInterface;
use FOS\MessageBundle\ModelManager\MessageManager as BaseMessageManager;
use FOS\MessageBundle\Model\ReadableInterface;
Expand Down Expand Up @@ -39,8 +40,6 @@ class MessageManager extends BaseMessageManager
protected $metaClass;

/**
* Constructor.
*
* @param DocumentManager $dm
* @param string $class
* @param string $metaClass
Expand All @@ -54,10 +53,7 @@ public function __construct(DocumentManager $dm, $class, $metaClass)
}

/**
* Tells how many unread, non-spam, messages this participant has
*
* @param ParticipantInterface $participant
* @return int the number of unread messages
* {@inheritDoc}
*/
public function getNbUnreadMessageByParticipant(ParticipantInterface $participant)
{
Expand All @@ -68,29 +64,19 @@ public function getNbUnreadMessageByParticipant(ParticipantInterface $participan
}

/**
* Marks the readable as read by this participant
* Must be applied directly to the storage,
* without modifying the readable state.
* We want to show the unread readables on the page,
* as well as marking the as read.
*
* @param ReadableInterface $readable
* @param ParticipantInterface $participant
* {@inheritDoc}
*/
public function markAsReadByParticipant(ReadableInterface $readable, ParticipantInterface $participant)
{
return $this->markIsReadByParticipant($readable, $participant, true);
$this->markIsReadByParticipant($readable, $participant, true);
}

/**
* Marks the readable as unread by this participant
*
* @param ReadableInterface $readable
* @param ParticipantInterface $participant
* {@inheritDoc}
*/
public function markAsUnreadByParticipant(ReadableInterface $readable, ParticipantInterface $participant)
{
return $this->markIsReadByParticipant($readable, $participant, false);
$this->markIsReadByParticipant($readable, $participant, false);
}

/**
Expand Down Expand Up @@ -167,10 +153,7 @@ protected function markIsReadByCondition(ParticipantInterface $participant, $isR
}

/**
* Saves a message
*
* @param MessageInterface $message
* @param Boolean $andFlush Whether to flush the changes (default true)
* {@inheritDoc}
*/
public function saveMessage(MessageInterface $message, $andFlush = true)
{
Expand All @@ -182,9 +165,7 @@ public function saveMessage(MessageInterface $message, $andFlush = true)
}

/**
* Returns the fully qualified comment thread class name
*
* @return string
* {@inheritDoc}
*/
public function getClass()
{
Expand All @@ -201,7 +182,7 @@ protected function createMessageMetadata()
return new $this->metaClass();
}

/**
/*
* DENORMALIZATION
*
* All following methods are relative to denormalization
Expand Down
Loading

0 comments on commit f63498c

Please sign in to comment.