diff --git a/src/Exception/ExpiredSignatureException.php b/src/Exception/ExpiredSignatureException.php index b88621c..98db780 100644 --- a/src/Exception/ExpiredSignatureException.php +++ b/src/Exception/ExpiredSignatureException.php @@ -1,19 +1,22 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ - namespace SymfonyCasts\Bundle\VerifyEmail\Exception; +use Exception; + /** * @author Jesse Rushlow * @author Ryan Weaver */ -final class ExpiredSignatureException extends \Exception implements VerifyEmailExceptionInterface +final class ExpiredSignatureException extends Exception implements VerifyEmailExceptionInterface { public function getReason(): string { diff --git a/src/Exception/InvalidSignatureException.php b/src/Exception/InvalidSignatureException.php index 52132d1..a71f35e 100644 --- a/src/Exception/InvalidSignatureException.php +++ b/src/Exception/InvalidSignatureException.php @@ -1,19 +1,22 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ - namespace SymfonyCasts\Bundle\VerifyEmail\Exception; +use Exception; + /** * @author Jesse Rushlow * @author Ryan Weaver */ -final class InvalidSignatureException extends \Exception implements VerifyEmailExceptionInterface +final class InvalidSignatureException extends Exception implements VerifyEmailExceptionInterface { public function getReason(): string { diff --git a/src/Exception/VerifyEmailExceptionInterface.php b/src/Exception/VerifyEmailExceptionInterface.php index 61e9bb7..3b8a5d3 100644 --- a/src/Exception/VerifyEmailExceptionInterface.php +++ b/src/Exception/VerifyEmailExceptionInterface.php @@ -1,21 +1,24 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ - namespace SymfonyCasts\Bundle\VerifyEmail\Exception; +use Throwable; + /** * An exception that is thrown by VerifyEmailHelperInterface::validateEmailConfirmation(). * * @author Jesse Rushlow * @author Ryan Weaver */ -interface VerifyEmailExceptionInterface extends \Throwable +interface VerifyEmailExceptionInterface extends Throwable { /** * Returns a safe string that describes why verification failed. diff --git a/src/Exception/VerifyEmailRuntimeException.php b/src/Exception/VerifyEmailRuntimeException.php index 75f34ce..ba17d6f 100644 --- a/src/Exception/VerifyEmailRuntimeException.php +++ b/src/Exception/VerifyEmailRuntimeException.php @@ -1,18 +1,21 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ - namespace SymfonyCasts\Bundle\VerifyEmail\Exception; +use RuntimeException; + /** * @author Jesse Rushlow */ -final class VerifyEmailRuntimeException extends \RuntimeException implements VerifyEmailExceptionInterface +final class VerifyEmailRuntimeException extends RuntimeException implements VerifyEmailExceptionInterface { public function getReason(): string { diff --git a/src/Exception/WrongEmailVerifyException.php b/src/Exception/WrongEmailVerifyException.php index 567777e..d0a2c0e 100644 --- a/src/Exception/WrongEmailVerifyException.php +++ b/src/Exception/WrongEmailVerifyException.php @@ -1,19 +1,22 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ - namespace SymfonyCasts\Bundle\VerifyEmail\Exception; +use Exception; + /** * @author Jesse Rushlow * @author Ryan Weaver */ -final class WrongEmailVerifyException extends \Exception implements VerifyEmailExceptionInterface +final class WrongEmailVerifyException extends Exception implements VerifyEmailExceptionInterface { public function getReason(): string { diff --git a/src/Factory/UriSignerFactory.php b/src/Factory/UriSignerFactory.php index c655310..5351319 100644 --- a/src/Factory/UriSignerFactory.php +++ b/src/Factory/UriSignerFactory.php @@ -1,14 +1,16 @@ * 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 SensitiveParameter; use Symfony\Component\HttpFoundation\UriSigner; /** @@ -19,10 +21,11 @@ * * @internal */ -final class UriSignerFactory +final readonly class UriSignerFactory { public function __construct( - #[\SensitiveParameter] + #[SensitiveParameter] + private string $secret, private string $parameter = '_hash', ) { diff --git a/src/Generator/VerifyEmailTokenGenerator.php b/src/Generator/VerifyEmailTokenGenerator.php index ccd05c1..960a7ba 100644 --- a/src/Generator/VerifyEmailTokenGenerator.php +++ b/src/Generator/VerifyEmailTokenGenerator.php @@ -1,14 +1,17 @@ * 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 SensitiveParameter; +use JsonException; use SymfonyCasts\Bundle\VerifyEmail\Exception\VerifyEmailRuntimeException; /** @@ -25,8 +28,8 @@ class VerifyEmailTokenGenerator * @param string $signingKey Unique, random, cryptographically secure string */ public function __construct( - #[\SensitiveParameter] - private string $signingKey, + #[SensitiveParameter] + private readonly string $signingKey, ) { } @@ -39,8 +42,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..f3c9c91 100644 --- a/src/Model/VerifyEmailSignatureComponents.php +++ b/src/Model/VerifyEmailSignatureComponents.php @@ -1,14 +1,18 @@ * 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 DateTimeInterface; +use DateInterval; +use DateTimeImmutable; use SymfonyCasts\Bundle\VerifyEmail\Exception\VerifyEmailRuntimeException; /** @@ -26,9 +30,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, ) { } @@ -43,7 +47,7 @@ public function getSignedUrl(): string /** * Get the length of time in seconds that a signature is valid for. */ - public function getExpiresAt(): \DateTimeInterface + public function getExpiresAt(): DateTimeInterface { return $this->expiresAt; } @@ -101,9 +105,9 @@ public function getExpirationMessageData(): array * * @throws VerifyEmailRuntimeException */ - public function getExpiresAtIntervalInstance(): \DateInterval + public function getExpiresAtIntervalInstance(): DateInterval { - $createdAtTime = \DateTimeImmutable::createFromFormat('U', (string) $this->generatedAt); + $createdAtTime = DateTimeImmutable::createFromFormat('U', (string) $this->generatedAt); if (false === $createdAtTime) { throw new VerifyEmailRuntimeException(\sprintf('Unable to create DateTimeInterface instance from "generatedAt": %s', $this->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..ea68331 100644 --- a/src/VerifyEmailHelper.php +++ b/src/VerifyEmailHelper.php @@ -1,14 +1,16 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ - namespace SymfonyCasts\Bundle\VerifyEmail; +use DateTimeImmutable; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\UriSigner; use Symfony\Component\Routing\Generator\UrlGeneratorInterface; @@ -23,7 +25,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 @@ -51,7 +53,7 @@ public function generateSignature(string $routeName, string $userId, string $use $signature = $this->uriSigner->sign($uri); - if (!$expiresAt = \DateTimeImmutable::createFromFormat('U', (string) $expiryTimestamp)) { + if (!$expiresAt = DateTimeImmutable::createFromFormat('U', (string) $expiryTimestamp)) { throw new VerifyEmailRuntimeException(\sprintf('Unable to create DateTimeImmutable from timestamp: %s', $expiryTimestamp)); } 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; diff --git a/tests/Integration/VerifyEmailBundleAutowireTest.php b/tests/Integration/VerifyEmailBundleAutowireTest.php index c7b1624..ab258ed 100644 --- a/tests/Integration/VerifyEmailBundleAutowireTest.php +++ b/tests/Integration/VerifyEmailBundleAutowireTest.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\Tests\Integration; use PHPUnit\Framework\TestCase; @@ -39,7 +40,4 @@ public function testVerifyEmailBundleInterfaceIsAutowiredByContainer(): void class VerifyEmailHelperAutowireTest { - public function __construct(VerifyEmailHelperInterface $helper) /** @phpstan-ignore-line constructor.unusedParameter */ - { - } } diff --git a/tests/Integration/VerifyEmailServiceDefinitionTest.php b/tests/Integration/VerifyEmailServiceDefinitionTest.php index d1b6b70..d769999 100644 --- a/tests/Integration/VerifyEmailServiceDefinitionTest.php +++ b/tests/Integration/VerifyEmailServiceDefinitionTest.php @@ -1,14 +1,16 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ - namespace SymfonyCasts\Bundle\VerifyEmail\Tests\Integration; +use Generator; use PHPUnit\Framework\TestCase; use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; use Symfony\Component\DependencyInjection\ContainerBuilder; @@ -20,7 +22,7 @@ */ final class VerifyEmailServiceDefinitionTest extends TestCase { - public function bundleServiceDefinitionDataProvider(): \Generator + public function bundleServiceDefinitionDataProvider(): Generator { $prefix = 'symfonycasts.verify_email.'; diff --git a/tests/VerifyEmailTestKernel.php b/tests/VerifyEmailTestKernel.php index 87485e9..a4cb166 100644 --- a/tests/VerifyEmailTestKernel.php +++ b/tests/VerifyEmailTestKernel.php @@ -1,14 +1,16 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ - namespace SymfonyCasts\Bundle\VerifyEmail\Tests; +use Override; use Symfony\Bundle\FrameworkBundle\FrameworkBundle; use Symfony\Component\Config\Loader\LoaderInterface; use Symfony\Component\DependencyInjection\ContainerBuilder; @@ -32,8 +34,8 @@ class VerifyEmailTestKernel extends Kernel */ public function __construct( private ?ContainerBuilder $builder = null, - private array $routes = [], - private array $extraBundles = [], + private readonly array $routes = [], + private readonly array $extraBundles = [], ) { parent::__construct('test', true); } @@ -51,13 +53,13 @@ public function registerBundles(): iterable public function registerContainerConfiguration(LoaderInterface $loader): void { - if (null === $this->builder) { + if (!$this->builder instanceof ContainerBuilder) { $this->builder = new ContainerBuilder(); } $builder = $this->builder; - $loader->load(function (ContainerBuilder $container) use ($builder) { + $loader->load(function (ContainerBuilder $container) use ($builder): void { $container->merge($builder); $container->loadFromExtension( 'framework', @@ -92,11 +94,13 @@ public function loadRoutes(LoaderInterface $loader): RouteCollection return $routes; } + #[Override] public function getCacheDir(): string { return sys_get_temp_dir().'/cache'.spl_object_hash($this); } + #[Override] public function getLogDir(): string { return sys_get_temp_dir().'/logs'.spl_object_hash($this);