From b44d20991a3b82dda25798af44b158fd69c7202a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81ngel=20Guzm=C3=A1n=20Maeso?= Date: Wed, 28 May 2025 13:23:29 +0200 Subject: [PATCH] feat: declare strict types and support php 8.4. No short namespaces import --- src/Exception/ExpiredSignatureException.php | 3 ++- src/Exception/InvalidSignatureException.php | 3 ++- src/Exception/VerifyEmailExceptionInterface.php | 3 ++- src/Exception/VerifyEmailRuntimeException.php | 3 ++- src/Exception/WrongEmailVerifyException.php | 3 ++- src/Factory/UriSignerFactory.php | 6 ++++-- src/Generator/VerifyEmailTokenGenerator.php | 9 +++++---- src/Model/VerifyEmailSignatureComponents.php | 9 +++++---- src/SymfonyCastsVerifyEmailBundle.php | 3 ++- src/Util/VerifyEmailQueryUtility.php | 3 ++- src/VerifyEmailHelper.php | 5 +++-- src/VerifyEmailHelperInterface.php | 3 ++- 12 files changed, 33 insertions(+), 20 deletions(-) diff --git a/src/Exception/ExpiredSignatureException.php b/src/Exception/ExpiredSignatureException.php index b88621c..2f39c77 100644 --- a/src/Exception/ExpiredSignatureException.php +++ b/src/Exception/ExpiredSignatureException.php @@ -1,12 +1,13 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ - namespace SymfonyCasts\Bundle\VerifyEmail\Exception; /** diff --git a/src/Exception/InvalidSignatureException.php b/src/Exception/InvalidSignatureException.php index 52132d1..3cafcb1 100644 --- a/src/Exception/InvalidSignatureException.php +++ b/src/Exception/InvalidSignatureException.php @@ -1,12 +1,13 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ - namespace SymfonyCasts\Bundle\VerifyEmail\Exception; /** diff --git a/src/Exception/VerifyEmailExceptionInterface.php b/src/Exception/VerifyEmailExceptionInterface.php index 61e9bb7..90de0c0 100644 --- a/src/Exception/VerifyEmailExceptionInterface.php +++ b/src/Exception/VerifyEmailExceptionInterface.php @@ -1,12 +1,13 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ - namespace SymfonyCasts\Bundle\VerifyEmail\Exception; /** diff --git a/src/Exception/VerifyEmailRuntimeException.php b/src/Exception/VerifyEmailRuntimeException.php index 75f34ce..b3747d4 100644 --- a/src/Exception/VerifyEmailRuntimeException.php +++ b/src/Exception/VerifyEmailRuntimeException.php @@ -1,12 +1,13 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ - namespace SymfonyCasts\Bundle\VerifyEmail\Exception; /** diff --git a/src/Exception/WrongEmailVerifyException.php b/src/Exception/WrongEmailVerifyException.php index 567777e..6649492 100644 --- a/src/Exception/WrongEmailVerifyException.php +++ b/src/Exception/WrongEmailVerifyException.php @@ -1,12 +1,13 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ - namespace SymfonyCasts\Bundle\VerifyEmail\Exception; /** diff --git a/src/Factory/UriSignerFactory.php b/src/Factory/UriSignerFactory.php index c655310..3e1437b 100644 --- a/src/Factory/UriSignerFactory.php +++ b/src/Factory/UriSignerFactory.php @@ -1,12 +1,13 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ - namespace SymfonyCasts\Bundle\VerifyEmail\Factory; use Symfony\Component\HttpFoundation\UriSigner; @@ -19,10 +20,11 @@ * * @internal */ -final class UriSignerFactory +final readonly class UriSignerFactory { public function __construct( #[\SensitiveParameter] + private string $secret, private string $parameter = '_hash', ) { diff --git a/src/Generator/VerifyEmailTokenGenerator.php b/src/Generator/VerifyEmailTokenGenerator.php index ccd05c1..3e61169 100644 --- a/src/Generator/VerifyEmailTokenGenerator.php +++ b/src/Generator/VerifyEmailTokenGenerator.php @@ -1,12 +1,13 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ - namespace SymfonyCasts\Bundle\VerifyEmail\Generator; use SymfonyCasts\Bundle\VerifyEmail\Exception\VerifyEmailRuntimeException; @@ -26,7 +27,7 @@ class VerifyEmailTokenGenerator */ public function __construct( #[\SensitiveParameter] - private string $signingKey, + private readonly string $signingKey, ) { } @@ -39,8 +40,8 @@ public function createToken(string $userId, string $email): string { try { $encodedData = json_encode([$userId, $email], \JSON_THROW_ON_ERROR); - } catch (\JsonException $exception) { - throw new VerifyEmailRuntimeException(message: 'Unable to create token. Invalid JSON.', previous: $exception); + } catch (\JsonException $jsonException) { + throw new VerifyEmailRuntimeException(message: 'Unable to create token. Invalid JSON.', previous: $jsonException); } return base64_encode(hash_hmac('sha256', $encodedData, $this->signingKey, true)); diff --git a/src/Model/VerifyEmailSignatureComponents.php b/src/Model/VerifyEmailSignatureComponents.php index 33cfec7..675030b 100644 --- a/src/Model/VerifyEmailSignatureComponents.php +++ b/src/Model/VerifyEmailSignatureComponents.php @@ -1,12 +1,13 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ - namespace SymfonyCasts\Bundle\VerifyEmail\Model; use SymfonyCasts\Bundle\VerifyEmail\Exception\VerifyEmailRuntimeException; @@ -26,9 +27,9 @@ final class VerifyEmailSignatureComponents * @param int $generatedAt timestamp when the signature was created */ public function __construct( - private \DateTimeInterface $expiresAt, - private string $uri, - private int $generatedAt, + private readonly \DateTimeInterface $expiresAt, + private readonly string $uri, + private readonly int $generatedAt, ) { } diff --git a/src/SymfonyCastsVerifyEmailBundle.php b/src/SymfonyCastsVerifyEmailBundle.php index 7909789..02c9f7a 100644 --- a/src/SymfonyCastsVerifyEmailBundle.php +++ b/src/SymfonyCastsVerifyEmailBundle.php @@ -1,12 +1,13 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ - namespace SymfonyCasts\Bundle\VerifyEmail; use Symfony\Component\Config\Definition\Configurator\DefinitionConfigurator; diff --git a/src/Util/VerifyEmailQueryUtility.php b/src/Util/VerifyEmailQueryUtility.php index 683230b..c112026 100644 --- a/src/Util/VerifyEmailQueryUtility.php +++ b/src/Util/VerifyEmailQueryUtility.php @@ -1,12 +1,13 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ - namespace SymfonyCasts\Bundle\VerifyEmail\Util; /** diff --git a/src/VerifyEmailHelper.php b/src/VerifyEmailHelper.php index 345728f..a53f6a8 100644 --- a/src/VerifyEmailHelper.php +++ b/src/VerifyEmailHelper.php @@ -1,12 +1,13 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ - namespace SymfonyCasts\Bundle\VerifyEmail; use Symfony\Component\HttpFoundation\Request; @@ -23,7 +24,7 @@ * @author Jesse Rushlow * @author Ryan Weaver */ -final class VerifyEmailHelper implements VerifyEmailHelperInterface +final readonly class VerifyEmailHelper implements VerifyEmailHelperInterface { /** * @param int $lifetime The length of time in seconds that a signed URI is valid for after it is created diff --git a/src/VerifyEmailHelperInterface.php b/src/VerifyEmailHelperInterface.php index 6ca5f20..c528f53 100644 --- a/src/VerifyEmailHelperInterface.php +++ b/src/VerifyEmailHelperInterface.php @@ -1,12 +1,13 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ - namespace SymfonyCasts\Bundle\VerifyEmail; use Symfony\Component\HttpFoundation\Request;