Skip to content

Commit c4b84c2

Browse files
committed
follow symfony coding standards
1 parent 9d7e037 commit c4b84c2

13 files changed

+35
-36
lines changed

.php-cs-fixer.dist.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
->setRules(array(
1313
'@Symfony' => true,
1414
'@Symfony:risky' => true,
15-
'native_function_invocation' => ['include' => ['@internal'], 'scope' => 'namespaced', 'strict' => true],
1615
'header_comment' => [
1716
'header' => <<<EOF
1817
This file is part of the SymfonyCasts ResetPasswordBundle package.

src/Command/ResetPasswordRemoveExpiredCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
5050

5151
$intRemoved = $this->cleaner->handleGarbageCollection(true);
5252

53-
$output->writeln(\sprintf('Garbage collection successful. Removed %s reset password request object(s).', $intRemoved));
53+
$output->writeln(sprintf('Garbage collection successful. Removed %s reset password request object(s).', $intRemoved));
5454

5555
return 0;
5656
}

src/Generator/ResetPasswordRandomGenerator.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ public function getRandomAlphaNumStr(): string
3030
while (($len = \strlen($string)) < 20) {
3131
$size = 20 - $len;
3232

33-
$bytes = \random_bytes($size);
33+
$bytes = random_bytes($size);
3434

35-
$string .= \substr(
36-
\str_replace(['/', '+', '='], '', \base64_encode($bytes)), 0, $size);
35+
$string .= substr(
36+
str_replace(['/', '+', '='], '', base64_encode($bytes)), 0, $size);
3737
}
3838

3939
return $string;

src/Generator/ResetPasswordTokenGenerator.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public function createToken(\DateTimeInterface $expiresAt, $userId, string $veri
5050

5151
$selector = $this->randomGenerator->getRandomAlphaNumStr();
5252

53-
$encodedData = \json_encode([$verifier, $userId, $expiresAt->getTimestamp()]);
53+
$encodedData = json_encode([$verifier, $userId, $expiresAt->getTimestamp()]);
5454

5555
return new ResetPasswordTokenComponents(
5656
$selector,
@@ -61,6 +61,6 @@ public function createToken(\DateTimeInterface $expiresAt, $userId, string $veri
6161

6262
private function getHashedToken(string $data): string
6363
{
64-
return \base64_encode(\hash_hmac('sha256', $data, $this->signingKey, true));
64+
return base64_encode(hash_hmac('sha256', $data, $this->signingKey, true));
6565
}
6666
}

src/Model/ResetPasswordRequestTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function getRequestedAt(): \DateTimeInterface
5252

5353
public function isExpired(): bool
5454
{
55-
return $this->expiresAt->getTimestamp() <= \time();
55+
return $this->expiresAt->getTimestamp() <= time();
5656
}
5757

5858
public function getExpiresAt(): \DateTimeInterface

src/Model/ResetPasswordToken.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ public function getExpirationMessageData(): array
135135
public function getExpiresAtIntervalInstance(): \DateInterval
136136
{
137137
if (null === $this->generatedAt) {
138-
throw new \LogicException(\sprintf('%s initialized without setting the $generatedAt timestamp.', self::class));
138+
throw new \LogicException(sprintf('%s initialized without setting the $generatedAt timestamp.', self::class));
139139
}
140140

141141
$createdAtTime = \DateTimeImmutable::createFromFormat('U', (string) $this->generatedAt);

src/ResetPasswordHelper.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public function generateResetToken(object $user): ResetPasswordToken
6868
throw new TooManyPasswordRequestsException($availableAt);
6969
}
7070

71-
$expiresAt = new \DateTimeImmutable(\sprintf('+%d seconds', $this->resetRequestLifetime));
71+
$expiresAt = new \DateTimeImmutable(sprintf('+%d seconds', $this->resetRequestLifetime));
7272

7373
$generatedAt = ($expiresAt->getTimestamp() - $this->resetRequestLifetime);
7474

@@ -120,10 +120,10 @@ public function validateTokenAndFetchUser(string $fullToken): object
120120
$hashedVerifierToken = $this->tokenGenerator->createToken(
121121
$resetRequest->getExpiresAt(),
122122
$this->repository->getUserIdentifier($user),
123-
\substr($fullToken, self::SELECTOR_LENGTH)
123+
substr($fullToken, self::SELECTOR_LENGTH)
124124
);
125125

126-
if (false === \hash_equals($resetRequest->getHashedToken(), $hashedVerifierToken->getHashedToken())) {
126+
if (false === hash_equals($resetRequest->getHashedToken(), $hashedVerifierToken->getHashedToken())) {
127127
throw new InvalidResetPasswordTokenException();
128128
}
129129

@@ -166,7 +166,7 @@ public function getTokenLifetime(): int
166166
*/
167167
public function generateFakeResetToken(): ResetPasswordToken
168168
{
169-
$expiresAt = new \DateTimeImmutable(\sprintf('+%d seconds', $this->resetRequestLifetime));
169+
$expiresAt = new \DateTimeImmutable(sprintf('+%d seconds', $this->resetRequestLifetime));
170170

171171
$generatedAt = ($expiresAt->getTimestamp() - $this->resetRequestLifetime);
172172

@@ -175,7 +175,7 @@ public function generateFakeResetToken(): ResetPasswordToken
175175

176176
private function findResetPasswordRequest(string $token): ?ResetPasswordRequestInterface
177177
{
178-
$selector = \substr($token, 0, self::SELECTOR_LENGTH);
178+
$selector = substr($token, 0, self::SELECTOR_LENGTH);
179179

180180
return $this->repository->findResetPasswordRequest($selector);
181181
}

tests/Fixtures/Entity/ResetPasswordTestFixtureRequest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public function getRequestedAt(): \DateTimeInterface
5555

5656
public function isExpired(): bool
5757
{
58-
return $this->expiresAt->getTimestamp() <= \time();
58+
return $this->expiresAt->getTimestamp() <= time();
5959
}
6060

6161
public function getExpiresAt(): \DateTimeInterface

tests/ResetPasswordTestKernel.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function __construct(ContainerBuilder $builder = null, array $routes = []
4747

4848
public function registerBundles(): iterable
4949
{
50-
return \array_merge(
50+
return array_merge(
5151
$this->extraBundles,
5252
[
5353
new FrameworkBundle(),
@@ -133,11 +133,11 @@ public function loadRoutes(LoaderInterface $loader): RouteCollection
133133

134134
public function getCacheDir()
135135
{
136-
return \sys_get_temp_dir().'/cache'.\spl_object_hash($this);
136+
return sys_get_temp_dir().'/cache'.spl_object_hash($this);
137137
}
138138

139139
public function getLogDir()
140140
{
141-
return \sys_get_temp_dir().'/logs'.\spl_object_hash($this);
141+
return sys_get_temp_dir().'/logs'.spl_object_hash($this);
142142
}
143143
}

tests/UnitTests/Generator/ResetPasswordTokenGeneratorTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,17 +64,17 @@ public function testHashedTokenIsCreatedWithExpectedParams(): void
6464
->willReturn(2020)
6565
;
6666

67-
$expected = \hash_hmac(
67+
$expected = hash_hmac(
6868
'sha256',
69-
\json_encode(['verifier', 'user1234', 2020]),
69+
json_encode(['verifier', 'user1234', 2020]),
7070
'key',
7171
true
7272
);
7373

7474
$generator = $this->getTokenGenerator();
7575
$result = $generator->createToken($this->mockExpiresAt, 'user1234');
7676

77-
self::assertSame(\base64_encode($expected), $result->getHashedToken());
77+
self::assertSame(base64_encode($expected), $result->getHashedToken());
7878
}
7979

8080
public function testHashedTokenIsCreatedUsingOptionVerifierParam(): void
@@ -95,17 +95,17 @@ public function testHashedTokenIsCreatedUsingOptionVerifierParam(): void
9595
->willReturn($date)
9696
;
9797

98-
$knownToken = \hash_hmac(
98+
$knownToken = hash_hmac(
9999
'sha256',
100-
\json_encode([$knownVerifier, $userId, $date]),
100+
json_encode([$knownVerifier, $userId, $date]),
101101
'key',
102102
true
103103
);
104104

105105
$generator = $this->getTokenGenerator();
106106
$result = $generator->createToken($this->mockExpiresAt, $userId, $knownVerifier);
107107

108-
self::assertSame(\base64_encode($knownToken), $result->getHashedToken());
108+
self::assertSame(base64_encode($knownToken), $result->getHashedToken());
109109
}
110110

111111
private function getTokenGenerator(): ResetPasswordTokenGenerator

0 commit comments

Comments
 (0)