Skip to content

Commit 341cea2

Browse files
committed
minor #709 Improved code thanks to PhpStorm and Php Inspections (javiereguiluz)
This PR was squashed before being merged into the master branch (closes #709). Discussion ---------- Improved code thanks to PhpStorm and Php Inspections Commits ------- 061b405 Improved code thanks to PhpStorm and Php Inspections
2 parents 68b0653 + 061b405 commit 341cea2

File tree

7 files changed

+13
-23
lines changed

7 files changed

+13
-23
lines changed

src/Command/AddUserCommand.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
199199

200200
$event = $stopwatch->stop('add-user-command');
201201
if ($output->isVerbose()) {
202-
$this->io->comment(sprintf('New user database id: %d / Elapsed time: %.2f ms / Consumed memory: %.2f MB', $user->getId(), $event->getDuration(), $event->getMemory() / pow(1024, 2)));
202+
$this->io->comment(sprintf('New user database id: %d / Elapsed time: %.2f ms / Consumed memory: %.2f MB', $user->getId(), $event->getDuration(), $event->getMemory() / (1024 ** 2)));
203203
}
204204
}
205205

src/DataFixtures/FixturesTrait.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ private function getRandomPostSummary(int $maxLength = 255): string
123123
{
124124
$phrases = $this->getPhrases();
125125

126-
$numPhrases = mt_rand(6, 12);
126+
$numPhrases = random_int(6, 12);
127127
shuffle($phrases);
128128
$phrases = array_slice($phrases, 0, $numPhrases - 1);
129129

@@ -138,7 +138,7 @@ private function getRandomCommentContent(): string
138138
{
139139
$phrases = $this->getPhrases();
140140

141-
$numPhrases = mt_rand(2, 15);
141+
$numPhrases = random_int(2, 15);
142142
shuffle($phrases);
143143

144144
return implode(' ', array_slice($phrases, 0, $numPhrases - 1));

src/DataFixtures/ORM/PostFixtures.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function load(ObjectManager $manager): void
5757
$post->setAuthor(0 === $i ? $this->getReference('jane-admin') : $this->getRandomUser());
5858

5959
// for aesthetic reasons, the first blog post always has 2 tags
60-
foreach ($this->getRandomTags($i > 0 ? mt_rand(0, 3) : 2) as $tag) {
60+
foreach ($this->getRandomTags($i > 0 ? random_int(0, 3) : 2) as $tag) {
6161
$post->addTag($tag);
6262
}
6363

src/Entity/User.php

+4-14
Original file line numberDiff line numberDiff line change
@@ -168,26 +168,16 @@ public function eraseCredentials(): void
168168
*/
169169
public function serialize(): string
170170
{
171-
return serialize([
172-
$this->id,
173-
$this->username,
174-
$this->password,
175-
// see section on salt below
176-
// $this->salt,
177-
]);
171+
// add $this->salt too if you don't use Bcrypt or Argon2i
172+
return serialize([$this->id, $this->username, $this->password]);
178173
}
179174

180175
/**
181176
* {@inheritdoc}
182177
*/
183178
public function unserialize($serialized): void
184179
{
185-
list(
186-
$this->id,
187-
$this->username,
188-
$this->password,
189-
// see section on salt below
190-
// $this->salt
191-
) = unserialize($serialized);
180+
// add $this->salt too if you don't use Bcrypt or Argon2i
181+
[$this->id, $this->username, $this->password] = unserialize($serialized, ['allowed_classes' => false]);
192182
}
193183
}

src/EventSubscriber/RedirectToPreferredLocaleSubscriber.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
class RedirectToPreferredLocaleSubscriber implements EventSubscriberInterface
2929
{
3030
private $urlGenerator;
31-
private $locales = [];
32-
private $defaultLocale = '';
31+
private $locales;
32+
private $defaultLocale;
3333

3434
public function __construct(UrlGeneratorInterface $urlGenerator, string $locales, string $defaultLocale = null)
3535
{

src/Form/Type/DateTimePickerType.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function __construct(MomentFormatConverter $converter)
4141
public function buildView(FormView $view, FormInterface $form, array $options)
4242
{
4343
$view->vars['attr']['data-date-format'] = $this->formatConverter->convert($options['format']);
44-
$view->vars['attr']['data-date-locale'] = mb_strtolower(strtr(\Locale::getDefault(), '_', '-'));
44+
$view->vars['attr']['data-date-locale'] = mb_strtolower(str_replace('_', '-', \Locale::getDefault()));
4545
}
4646

4747
/**

tests/Form/DataTransformer/TagArrayToStringTransformerTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public function testTransform()
106106
*
107107
* @return TagArrayToStringTransformer
108108
*/
109-
private function getMockedTransformer($findByReturnValues = [])
109+
private function getMockedTransformer(array $findByReturnValues = []): TagArrayToStringTransformer
110110
{
111111
$tagRepository = $this->getMockBuilder(EntityRepository::class)
112112
->disableOriginalConstructor()
@@ -133,7 +133,7 @@ private function getMockedTransformer($findByReturnValues = [])
133133
*
134134
* @return Tag
135135
*/
136-
private function createTag($name)
136+
private function createTag($name): Tag
137137
{
138138
$tag = new Tag();
139139
$tag->setName($name);

0 commit comments

Comments
 (0)