Skip to content

Commit cdfee5e

Browse files
authored
Merge pull request #288 from FriendsOfSymfony/fix-287
Fix #287 and improve CS/readability of various parts of the code
2 parents d33c18a + 88c3dea commit cdfee5e

File tree

69 files changed

+245
-567
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+245
-567
lines changed

Command/MongoDBMigrateMetadataCommand.php

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
namespace FOS\MessageBundle\Command;
44

55
use Doctrine\Common\Persistence\ManagerRegistry;
6+
use FOS\MessageBundle\Document\Message;
7+
use FOS\MessageBundle\Document\Thread;
68
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
79
use Symfony\Component\Console\Input\InputArgument;
810
use Symfony\Component\Console\Input\InputInterface;
@@ -37,7 +39,7 @@ class MongoDBMigrateMetadataCommand extends ContainerAwareCommand
3739
private $printStatusCallback;
3840

3941
/**
40-
* @see Symfony\Component\Console\Command\Command::isEnabled()
42+
* {@inheritdoc}
4143
*/
4244
public function isEnabled()
4345
{
@@ -49,7 +51,7 @@ public function isEnabled()
4951
}
5052

5153
/**
52-
* @see Symfony\Component\Console\Command\Command::configure()
54+
* {@inheritdoc}
5355
*/
5456
protected function configure()
5557
{
@@ -92,7 +94,7 @@ protected function configure()
9294
}
9395

9496
/**
95-
* @see Symfony\Bundle\FrameworkBundle\Command\Command::initialize()
97+
* {@inheritdoc}
9698
*/
9799
protected function initialize(InputInterface $input, OutputInterface $output)
98100
{
@@ -113,7 +115,7 @@ protected function initialize(InputInterface $input, OutputInterface $output)
113115
}
114116

115117
/**
116-
* @see Symfony\Component\Console\Command\Command::execute()
118+
* {@inheritdoc}
117119
*/
118120
protected function execute(InputInterface $input, OutputInterface $output)
119121
{
@@ -122,13 +124,11 @@ protected function execute(InputInterface $input, OutputInterface $output)
122124

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

128130
/**
129131
* Migrate message documents
130-
*
131-
* @param OutputInterface $output
132132
*/
133133
private function migrateMessages(OutputInterface $output)
134134
{
@@ -175,8 +175,6 @@ private function migrateMessages(OutputInterface $output)
175175

176176
/**
177177
* Migrate thread documents
178-
*
179-
* @param OutputInterface $output
180178
*/
181179
private function migrateThreads(OutputInterface $output)
182180
{
@@ -233,8 +231,6 @@ private function migrateThreads(OutputInterface $output)
233231
*
234232
* By default, Mongo will not include "$db" when creating the participant
235233
* reference. We'll add that manually to be consistent with Doctrine.
236-
*
237-
* @param array &$message
238234
*/
239235
private function createMessageMetadata(array &$message)
240236
{
@@ -253,7 +249,7 @@ private function createMessageMetadata(array &$message)
253249
/**
254250
* Sets the unreadForParticipants array on the message.
255251
*
256-
* @see FOS\MessageBundle\Document\Message::doEnsureUnreadForParticipantsArray()
252+
* @see Message::doEnsureUnreadForParticipantsArray()
257253
* @param array &$message
258254
*/
259255
private function createMessageUnreadForParticipants(array &$message)
@@ -331,7 +327,7 @@ private function createThreadLastMessageDate(array &$thread)
331327
/**
332328
* Sets the active participant arrays on the thread.
333329
*
334-
* @see FOS\MessageBundle\Document\Thread::doEnsureActiveParticipantArrays()
330+
* @see Thread::doEnsureActiveParticipantArrays()
335331
* @param array $thread
336332
*/
337333
private function createThreadActiveParticipantArrays(array &$thread)
@@ -342,7 +338,7 @@ private function createThreadActiveParticipantArrays(array &$thread)
342338

343339
foreach ($thread['participants'] as $participantRef) {
344340
foreach ($thread['metadata'] as $metadata) {
345-
if ($participantRef['$id'] == $metadata['participant']['$id'] && $metadata['isDeleted']) {
341+
if ($metadata['isDeleted'] && $participantRef['$id'] === $metadata['participant']['$id']) {
346342
continue 2;
347343
}
348344
}

Composer/ComposerInterface.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace FOS\MessageBundle\Composer;
44

5+
use FOS\MessageBundle\MessageBuilder\AbstractMessageBuilder;
56
use FOS\MessageBundle\Model\ThreadInterface;
67

78
/**
@@ -14,14 +15,14 @@ interface ComposerInterface
1415
/**
1516
* Starts composing a message, starting a new thread
1617
*
17-
* @return MessageBuilderInterface
18+
* @return AbstractMessageBuilder
1819
*/
19-
function newThread();
20+
public function newThread();
2021

2122
/**
2223
* Starts composing a message in a reply to a thread
2324
*
24-
* @return MessageBuilderInterface
25+
* @return AbstractMessageBuilder
2526
*/
26-
function reply(ThreadInterface $thread);
27+
public function reply(ThreadInterface $thread);
2728
}

Controller/MessageController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
namespace FOS\MessageBundle\Controller;
44

5-
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
65
use Symfony\Component\DependencyInjection\ContainerAware;
76
use Symfony\Component\HttpFoundation\RedirectResponse;
87
use FOS\MessageBundle\Provider\ProviderInterface;
8+
use Symfony\Component\HttpFoundation\Response;
99

1010
class MessageController extends ContainerAware
1111
{

DataTransformer/RecipientsDataTransformer.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use Symfony\Component\Form\Exception\TransformationFailedException;
66
use Symfony\Component\Form\Exception\UnexpectedTypeException;
77
use Symfony\Component\Security\Core\User\UserInterface;
8-
use Doctrine\Common\Persistence\ObjectManager;
98
use Doctrine\Common\Collections\Collection;
109
use Doctrine\Common\Collections\ArrayCollection;
1110
/**
@@ -20,9 +19,6 @@ class RecipientsDataTransformer implements DataTransformerInterface
2019
*/
2120
private $userToUsernameTransformer;
2221

23-
/**
24-
* @param DataTransformerInterface $userToUsernameTransformer
25-
*/
2622
public function __construct(DataTransformerInterface $userToUsernameTransformer)
2723
{
2824
$this->userToUsernameTransformer = $userToUsernameTransformer;
@@ -37,8 +33,8 @@ public function __construct(DataTransformerInterface $userToUsernameTransformer)
3733
*/
3834
public function transform($recipients)
3935
{
40-
if ($recipients === null || $recipients->count() == 0) {
41-
return "";
36+
if ($recipients === null || $recipients->count() === 0) {
37+
return '';
4238
}
4339

4440
$usernames = array();
@@ -84,4 +80,4 @@ public function reverseTransform($usernames)
8480

8581
return $recipients;
8682
}
87-
}
83+
}

Deleter/Deleter.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace FOS\MessageBundle\Deleter;
44

5+
use FOS\MessageBundle\Model\ParticipantInterface;
56
use FOS\MessageBundle\Security\AuthorizerInterface;
67
use FOS\MessageBundle\Model\ThreadInterface;
78
use FOS\MessageBundle\Security\ParticipantProviderInterface;
@@ -46,9 +47,7 @@ public function __construct(AuthorizerInterface $authorizer, ParticipantProvider
4647
}
4748

4849
/**
49-
* Marks the thread as deleted by the current authenticated user
50-
*
51-
* @param ThreadInterface $thread
50+
* {@inheritdoc}
5251
*/
5352
public function markAsDeleted(ThreadInterface $thread)
5453
{
@@ -61,9 +60,7 @@ public function markAsDeleted(ThreadInterface $thread)
6160
}
6261

6362
/**
64-
* Marks the thread as undeleted by the current authenticated user
65-
*
66-
* @param ThreadInterface $thread
63+
* {@inheritdoc}
6764
*/
6865
public function markAsUndeleted(ThreadInterface $thread)
6966
{

Deleter/DeleterInterface.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,11 @@ interface DeleterInterface
1313
{
1414
/**
1515
* Marks the thread as deleted by the current authenticated user
16-
*
17-
* @param ThreadInterface $thread
1816
*/
19-
function markAsDeleted(ThreadInterface $thread);
17+
public function markAsDeleted(ThreadInterface $thread);
2018

2119
/**
2220
* Marks the thread as undeleted by the current authenticated user
23-
*
24-
* @param ThreadInterface $thread
2521
*/
26-
function markAsUndeleted(ThreadInterface $thread);
22+
public function markAsUndeleted(ThreadInterface $thread);
2723
}

DependencyInjection/Configuration.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace FOS\MessageBundle\DependencyInjection;
44

55
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
6-
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
76
use Symfony\Component\Config\Definition\ConfigurationInterface;
87

98
/**

Document/Message.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,14 @@ abstract class Message extends BaseMessage
2323
protected $unreadForParticipants = array();
2424

2525
/**
26-
* @param boolean
27-
* @return null
26+
* @param boolean $isSpam
2827
*/
2928
public function setIsSpam($isSpam)
3029
{
3130
$this->isSpam = (boolean) $isSpam;
3231
}
3332

34-
/**
33+
/*
3534
* DENORMALIZATION
3635
*
3736
* All following methods are relative to denormalization

Document/Thread.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33
namespace FOS\MessageBundle\Document;
44

55
use FOS\MessageBundle\Model\Thread as AbstractThread;
6-
use FOS\MessageBundle\Model\MessageInterface;
7-
use Doctrine\Common\Collections\Collection;
8-
use Doctrine\Common\Collections\ArrayCollection;
96
use FOS\MessageBundle\Model\ParticipantInterface;
107

118
abstract class Thread extends AbstractThread
@@ -16,7 +13,7 @@ abstract class Thread extends AbstractThread
1613
* This denormalization field is used for sorting threads in the inbox and
1714
* sent list.
1815
*
19-
* @var DateTime
16+
* @var \DateTime
2017
*/
2118
protected $lastMessageDate;
2219

@@ -69,7 +66,7 @@ public function getParticipants()
6966
* If it already exists, nothing is done.
7067
*
7168
* @param ParticipantInterface $participant
72-
* @return null
69+
* @return void
7370
*/
7471
public function addParticipant(ParticipantInterface $participant)
7572
{
@@ -89,7 +86,7 @@ public function isParticipant(ParticipantInterface $participant)
8986
return $this->participants->contains($participant);
9087
}
9188

92-
/**
89+
/*
9390
* DENORMALIZATION
9491
*
9592
* All following methods are relative to denormalization

DocumentManager/MessageManager.php

Lines changed: 9 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Doctrine\ODM\MongoDB\DocumentManager;
66
use FOS\MessageBundle\Document\Message;
7+
use FOS\MessageBundle\Document\MessageMetadata;
78
use FOS\MessageBundle\Model\MessageInterface;
89
use FOS\MessageBundle\ModelManager\MessageManager as BaseMessageManager;
910
use FOS\MessageBundle\Model\ReadableInterface;
@@ -39,8 +40,6 @@ class MessageManager extends BaseMessageManager
3940
protected $metaClass;
4041

4142
/**
42-
* Constructor.
43-
*
4443
* @param DocumentManager $dm
4544
* @param string $class
4645
* @param string $metaClass
@@ -54,10 +53,7 @@ public function __construct(DocumentManager $dm, $class, $metaClass)
5453
}
5554

5655
/**
57-
* Tells how many unread, non-spam, messages this participant has
58-
*
59-
* @param ParticipantInterface $participant
60-
* @return int the number of unread messages
56+
* {@inheritDoc}
6157
*/
6258
public function getNbUnreadMessageByParticipant(ParticipantInterface $participant)
6359
{
@@ -68,29 +64,19 @@ public function getNbUnreadMessageByParticipant(ParticipantInterface $participan
6864
}
6965

7066
/**
71-
* Marks the readable as read by this participant
72-
* Must be applied directly to the storage,
73-
* without modifying the readable state.
74-
* We want to show the unread readables on the page,
75-
* as well as marking the as read.
76-
*
77-
* @param ReadableInterface $readable
78-
* @param ParticipantInterface $participant
67+
* {@inheritDoc}
7968
*/
8069
public function markAsReadByParticipant(ReadableInterface $readable, ParticipantInterface $participant)
8170
{
82-
return $this->markIsReadByParticipant($readable, $participant, true);
71+
$this->markIsReadByParticipant($readable, $participant, true);
8372
}
8473

8574
/**
86-
* Marks the readable as unread by this participant
87-
*
88-
* @param ReadableInterface $readable
89-
* @param ParticipantInterface $participant
75+
* {@inheritDoc}
9076
*/
9177
public function markAsUnreadByParticipant(ReadableInterface $readable, ParticipantInterface $participant)
9278
{
93-
return $this->markIsReadByParticipant($readable, $participant, false);
79+
$this->markIsReadByParticipant($readable, $participant, false);
9480
}
9581

9682
/**
@@ -167,10 +153,7 @@ protected function markIsReadByCondition(ParticipantInterface $participant, $isR
167153
}
168154

169155
/**
170-
* Saves a message
171-
*
172-
* @param MessageInterface $message
173-
* @param Boolean $andFlush Whether to flush the changes (default true)
156+
* {@inheritDoc}
174157
*/
175158
public function saveMessage(MessageInterface $message, $andFlush = true)
176159
{
@@ -182,9 +165,7 @@ public function saveMessage(MessageInterface $message, $andFlush = true)
182165
}
183166

184167
/**
185-
* Returns the fully qualified comment thread class name
186-
*
187-
* @return string
168+
* {@inheritDoc}
188169
*/
189170
public function getClass()
190171
{
@@ -201,7 +182,7 @@ protected function createMessageMetadata()
201182
return new $this->metaClass();
202183
}
203184

204-
/**
185+
/*
205186
* DENORMALIZATION
206187
*
207188
* All following methods are relative to denormalization

0 commit comments

Comments
 (0)