Skip to content

Commit

Permalink
minor #709 Improved code thanks to PhpStorm and Php Inspections (javi…
Browse files Browse the repository at this point in the history
…ereguiluz)

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
  • Loading branch information
javiereguiluz committed Nov 28, 2017
2 parents 68b0653 + 061b405 commit 341cea2
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/Command/AddUserCommand.php
Expand Up @@ -199,7 +199,7 @@ protected function execute(InputInterface $input, OutputInterface $output)

$event = $stopwatch->stop('add-user-command');
if ($output->isVerbose()) {
$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)));
$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)));
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/DataFixtures/FixturesTrait.php
Expand Up @@ -123,7 +123,7 @@ private function getRandomPostSummary(int $maxLength = 255): string
{
$phrases = $this->getPhrases();

$numPhrases = mt_rand(6, 12);
$numPhrases = random_int(6, 12);
shuffle($phrases);
$phrases = array_slice($phrases, 0, $numPhrases - 1);

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

$numPhrases = mt_rand(2, 15);
$numPhrases = random_int(2, 15);
shuffle($phrases);

return implode(' ', array_slice($phrases, 0, $numPhrases - 1));
Expand Down
2 changes: 1 addition & 1 deletion src/DataFixtures/ORM/PostFixtures.php
Expand Up @@ -57,7 +57,7 @@ public function load(ObjectManager $manager): void
$post->setAuthor(0 === $i ? $this->getReference('jane-admin') : $this->getRandomUser());

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

Expand Down
18 changes: 4 additions & 14 deletions src/Entity/User.php
Expand Up @@ -168,26 +168,16 @@ public function eraseCredentials(): void
*/
public function serialize(): string
{
return serialize([
$this->id,
$this->username,
$this->password,
// see section on salt below
// $this->salt,
]);
// add $this->salt too if you don't use Bcrypt or Argon2i
return serialize([$this->id, $this->username, $this->password]);
}

/**
* {@inheritdoc}
*/
public function unserialize($serialized): void
{
list(
$this->id,
$this->username,
$this->password,
// see section on salt below
// $this->salt
) = unserialize($serialized);
// add $this->salt too if you don't use Bcrypt or Argon2i
[$this->id, $this->username, $this->password] = unserialize($serialized, ['allowed_classes' => false]);
}
}
4 changes: 2 additions & 2 deletions src/EventSubscriber/RedirectToPreferredLocaleSubscriber.php
Expand Up @@ -28,8 +28,8 @@
class RedirectToPreferredLocaleSubscriber implements EventSubscriberInterface
{
private $urlGenerator;
private $locales = [];
private $defaultLocale = '';
private $locales;
private $defaultLocale;

public function __construct(UrlGeneratorInterface $urlGenerator, string $locales, string $defaultLocale = null)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Form/Type/DateTimePickerType.php
Expand Up @@ -41,7 +41,7 @@ public function __construct(MomentFormatConverter $converter)
public function buildView(FormView $view, FormInterface $form, array $options)
{
$view->vars['attr']['data-date-format'] = $this->formatConverter->convert($options['format']);
$view->vars['attr']['data-date-locale'] = mb_strtolower(strtr(\Locale::getDefault(), '_', '-'));
$view->vars['attr']['data-date-locale'] = mb_strtolower(str_replace('_', '-', \Locale::getDefault()));
}

/**
Expand Down
Expand Up @@ -106,7 +106,7 @@ public function testTransform()
*
* @return TagArrayToStringTransformer
*/
private function getMockedTransformer($findByReturnValues = [])
private function getMockedTransformer(array $findByReturnValues = []): TagArrayToStringTransformer
{
$tagRepository = $this->getMockBuilder(EntityRepository::class)
->disableOriginalConstructor()
Expand All @@ -133,7 +133,7 @@ private function getMockedTransformer($findByReturnValues = [])
*
* @return Tag
*/
private function createTag($name)
private function createTag($name): Tag
{
$tag = new Tag();
$tag->setName($name);
Expand Down

0 comments on commit 341cea2

Please sign in to comment.