diff --git a/src/Command/AddUserCommand.php b/src/Command/AddUserCommand.php index fb8169408..1456766a8 100644 --- a/src/Command/AddUserCommand.php +++ b/src/Command/AddUserCommand.php @@ -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))); } } diff --git a/src/DataFixtures/FixturesTrait.php b/src/DataFixtures/FixturesTrait.php index 16ecdf0f2..334aed0dc 100644 --- a/src/DataFixtures/FixturesTrait.php +++ b/src/DataFixtures/FixturesTrait.php @@ -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); @@ -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)); diff --git a/src/DataFixtures/ORM/PostFixtures.php b/src/DataFixtures/ORM/PostFixtures.php index d0d16cc5f..29b147e9c 100644 --- a/src/DataFixtures/ORM/PostFixtures.php +++ b/src/DataFixtures/ORM/PostFixtures.php @@ -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); } diff --git a/src/Entity/User.php b/src/Entity/User.php index 42e5da350..a2f36c33b 100644 --- a/src/Entity/User.php +++ b/src/Entity/User.php @@ -168,13 +168,8 @@ 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]); } /** @@ -182,12 +177,7 @@ public function serialize(): string */ 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]); } } diff --git a/src/EventSubscriber/RedirectToPreferredLocaleSubscriber.php b/src/EventSubscriber/RedirectToPreferredLocaleSubscriber.php index 7684bc588..477359d1e 100644 --- a/src/EventSubscriber/RedirectToPreferredLocaleSubscriber.php +++ b/src/EventSubscriber/RedirectToPreferredLocaleSubscriber.php @@ -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) { diff --git a/src/Form/Type/DateTimePickerType.php b/src/Form/Type/DateTimePickerType.php index dea737747..1ae608b60 100644 --- a/src/Form/Type/DateTimePickerType.php +++ b/src/Form/Type/DateTimePickerType.php @@ -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())); } /** diff --git a/tests/Form/DataTransformer/TagArrayToStringTransformerTest.php b/tests/Form/DataTransformer/TagArrayToStringTransformerTest.php index 704536f1e..290242cb7 100644 --- a/tests/Form/DataTransformer/TagArrayToStringTransformerTest.php +++ b/tests/Form/DataTransformer/TagArrayToStringTransformerTest.php @@ -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() @@ -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);