Skip to content

feat: declare strict types and support php 8.4 #205

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/Exception/ExpiredSignatureException.php
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
<?php

declare(strict_types=1);

/*
* This file is part of the SymfonyCasts VerifyEmailBundle package.
* Copyright (c) SymfonyCasts <https://symfonycasts.com/>
* 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 <jr@rushlow.dev>
* @author Ryan Weaver <ryan@symfonycasts.com>
*/
final class ExpiredSignatureException extends \Exception implements VerifyEmailExceptionInterface
final class ExpiredSignatureException extends Exception implements VerifyEmailExceptionInterface
{
public function getReason(): string
{
Expand Down
7 changes: 5 additions & 2 deletions src/Exception/InvalidSignatureException.php
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
<?php

declare(strict_types=1);

/*
* This file is part of the SymfonyCasts VerifyEmailBundle package.
* Copyright (c) SymfonyCasts <https://symfonycasts.com/>
* 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 <jr@rushlow.dev>
* @author Ryan Weaver <ryan@symfonycasts.com>
*/
final class InvalidSignatureException extends \Exception implements VerifyEmailExceptionInterface
final class InvalidSignatureException extends Exception implements VerifyEmailExceptionInterface
{
public function getReason(): string
{
Expand Down
7 changes: 5 additions & 2 deletions src/Exception/VerifyEmailExceptionInterface.php
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
<?php

declare(strict_types=1);

/*
* This file is part of the SymfonyCasts VerifyEmailBundle package.
* Copyright (c) SymfonyCasts <https://symfonycasts.com/>
* 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 <jr@rushlow.dev>
* @author Ryan Weaver <ryan@symfonycasts.com>
*/
interface VerifyEmailExceptionInterface extends \Throwable
interface VerifyEmailExceptionInterface extends Throwable
{
/**
* Returns a safe string that describes why verification failed.
Expand Down
7 changes: 5 additions & 2 deletions src/Exception/VerifyEmailRuntimeException.php
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
<?php

declare(strict_types=1);

/*
* This file is part of the SymfonyCasts VerifyEmailBundle package.
* Copyright (c) SymfonyCasts <https://symfonycasts.com/>
* 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 <jr@rushlow.dev>
*/
final class VerifyEmailRuntimeException extends \RuntimeException implements VerifyEmailExceptionInterface
final class VerifyEmailRuntimeException extends RuntimeException implements VerifyEmailExceptionInterface
{
public function getReason(): string
{
Expand Down
7 changes: 5 additions & 2 deletions src/Exception/WrongEmailVerifyException.php
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
<?php

declare(strict_types=1);

/*
* This file is part of the SymfonyCasts VerifyEmailBundle package.
* Copyright (c) SymfonyCasts <https://symfonycasts.com/>
* 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 <jr@rushlow.dev>
* @author Ryan Weaver <ryan@symfonycasts.com>
*/
final class WrongEmailVerifyException extends \Exception implements VerifyEmailExceptionInterface
final class WrongEmailVerifyException extends Exception implements VerifyEmailExceptionInterface
{
public function getReason(): string
{
Expand Down
9 changes: 6 additions & 3 deletions src/Factory/UriSignerFactory.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
<?php

declare(strict_types=1);

/*
* This file is part of the SymfonyCasts VerifyEmailBundle package.
* Copyright (c) SymfonyCasts <https://symfonycasts.com/>
* 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;

/**
Expand All @@ -19,10 +21,11 @@
*
* @internal
*/
final class UriSignerFactory
final readonly class UriSignerFactory
{
public function __construct(
#[\SensitiveParameter]
#[SensitiveParameter]

private string $secret,
private string $parameter = '_hash',
) {
Expand Down
13 changes: 8 additions & 5 deletions src/Generator/VerifyEmailTokenGenerator.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
<?php

declare(strict_types=1);

/*
* This file is part of the SymfonyCasts VerifyEmailBundle package.
* Copyright (c) SymfonyCasts <https://symfonycasts.com/>
* 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;

/**
Expand All @@ -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,
) {
}

Expand All @@ -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));
Expand Down
18 changes: 11 additions & 7 deletions src/Model/VerifyEmailSignatureComponents.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
<?php

declare(strict_types=1);

/*
* This file is part of the SymfonyCasts VerifyEmailBundle package.
* Copyright (c) SymfonyCasts <https://symfonycasts.com/>
* 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;

/**
Expand All @@ -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,
) {
}

Expand All @@ -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;
}
Expand Down Expand Up @@ -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));
Expand Down
3 changes: 2 additions & 1 deletion src/SymfonyCastsVerifyEmailBundle.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
<?php

declare(strict_types=1);

/*
* This file is part of the SymfonyCasts VerifyEmailBundle package.
* Copyright (c) SymfonyCasts <https://symfonycasts.com/>
* 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;
Expand Down
3 changes: 2 additions & 1 deletion src/Util/VerifyEmailQueryUtility.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
<?php

declare(strict_types=1);

/*
* This file is part of the SymfonyCasts VerifyEmailBundle package.
* Copyright (c) SymfonyCasts <https://symfonycasts.com/>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace SymfonyCasts\Bundle\VerifyEmail\Util;

/**
Expand Down
8 changes: 5 additions & 3 deletions src/VerifyEmailHelper.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
<?php

declare(strict_types=1);

/*
* This file is part of the SymfonyCasts VerifyEmailBundle package.
* Copyright (c) SymfonyCasts <https://symfonycasts.com/>
* 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;
Expand All @@ -23,7 +25,7 @@
* @author Jesse Rushlow <jr@rushlow.dev>
* @author Ryan Weaver <ryan@symfonycasts.com>
*/
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
Expand Down Expand Up @@ -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));
}

Expand Down
3 changes: 2 additions & 1 deletion src/VerifyEmailHelperInterface.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
<?php

declare(strict_types=1);

/*
* This file is part of the SymfonyCasts VerifyEmailBundle package.
* Copyright (c) SymfonyCasts <https://symfonycasts.com/>
* 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;
Expand Down
6 changes: 2 additions & 4 deletions tests/Integration/VerifyEmailBundleAutowireTest.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
<?php

declare(strict_types=1);

/*
* This file is part of the SymfonyCasts VerifyEmailBundle package.
* Copyright (c) SymfonyCasts <https://symfonycasts.com/>
* 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;
Expand Down Expand Up @@ -39,7 +40,4 @@ public function testVerifyEmailBundleInterfaceIsAutowiredByContainer(): void

class VerifyEmailHelperAutowireTest
{
public function __construct(VerifyEmailHelperInterface $helper) /** @phpstan-ignore-line constructor.unusedParameter */
{
}
}
6 changes: 4 additions & 2 deletions tests/Integration/VerifyEmailServiceDefinitionTest.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
<?php

declare(strict_types=1);

/*
* This file is part of the SymfonyCasts VerifyEmailBundle package.
* Copyright (c) SymfonyCasts <https://symfonycasts.com/>
* 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;
Expand All @@ -20,7 +22,7 @@
*/
final class VerifyEmailServiceDefinitionTest extends TestCase
{
public function bundleServiceDefinitionDataProvider(): \Generator
public function bundleServiceDefinitionDataProvider(): Generator
{
$prefix = 'symfonycasts.verify_email.';

Expand Down
Loading
Loading