Skip to content

Commit

Permalink
Update classes to readonly and refactor logger
Browse files Browse the repository at this point in the history
Updated several classes in the codebase to have the readonly keyword in the class definition. Also amended the logger from a readonly to a standard private property across various constructors, as well as refactored constant definitions that mistakenly had their types declared. This brings the code in line with stricter typing rules
  • Loading branch information
Spomky committed Jul 11, 2024
1 parent ef08816 commit 0eab3e4
Show file tree
Hide file tree
Showing 55 changed files with 274 additions and 274 deletions.
4 changes: 2 additions & 2 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

return static function (RectorConfig $config): void {
$config->import(SetList::DEAD_CODE);
$config->import(LevelSetList::UP_TO_PHP_81);
$config->import(LevelSetList::UP_TO_PHP_82);
$config->import(SymfonySetList::SYMFONY_60);
$config->import(SymfonySetList::SYMFONY_50_TYPES);
$config->import(SymfonySetList::SYMFONY_52_VALIDATOR_ATTRIBUTES);
Expand All @@ -40,7 +40,7 @@
ReadOnlyPropertyRector::class => [__DIR__ . '/src/metadata-service/src/Statement/MetadataStatement.php'],
PreferPHPUnitThisCallRector::class,
]);
$config->phpVersion(PhpVersion::PHP_81);
$config->phpVersion(PhpVersion::PHP_82);
$config->parallel();
$config->importNames();
$config->importShortClasses();
Expand Down
12 changes: 6 additions & 6 deletions src/symfony/src/Controller/AssertionRequestController.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
use Webauthn\Bundle\Security\Storage\Item;
use Webauthn\Bundle\Security\Storage\OptionsStorage;

final class AssertionRequestController
final readonly class AssertionRequestController
{
public function __construct(
private readonly PublicKeyCredentialRequestOptionsBuilder $optionsBuilder,
private readonly OptionsStorage $optionsStorage,
private readonly RequestOptionsHandler $optionsHandler,
private readonly FailureHandler|AuthenticationFailureHandlerInterface $failureHandler,
private readonly LoggerInterface $logger,
private PublicKeyCredentialRequestOptionsBuilder $optionsBuilder,
private OptionsStorage $optionsStorage,
private RequestOptionsHandler $optionsHandler,
private FailureHandler|AuthenticationFailureHandlerInterface $failureHandler,
private LoggerInterface $logger,
) {
}

Expand Down
14 changes: 7 additions & 7 deletions src/symfony/src/Controller/AttestationRequestController.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@
use Webauthn\Bundle\Security\Storage\Item;
use Webauthn\Bundle\Security\Storage\OptionsStorage;

final class AttestationRequestController
final readonly class AttestationRequestController
{
public function __construct(
private readonly PublicKeyCredentialCreationOptionsBuilder $extractor,
private readonly UserEntityGuesser $userEntityGuesser,
private readonly OptionsStorage $optionsStorage,
private readonly CreationOptionsHandler $creationOptionsHandler,
private readonly FailureHandler|AuthenticationFailureHandlerInterface $failureHandler,
private readonly bool $hideExistingExcludedCredentials = false,
private PublicKeyCredentialCreationOptionsBuilder $extractor,
private UserEntityGuesser $userEntityGuesser,
private OptionsStorage $optionsStorage,
private CreationOptionsHandler $creationOptionsHandler,
private FailureHandler|AuthenticationFailureHandlerInterface $failureHandler,
private bool $hideExistingExcludedCredentials = false,
) {
}

Expand Down
14 changes: 7 additions & 7 deletions src/symfony/src/Controller/AttestationResponseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@
use Webauthn\PublicKeyCredentialCreationOptions;
use Webauthn\PublicKeyCredentialUserEntity;

final class AttestationResponseController
final readonly class AttestationResponseController
{
public function __construct(
private readonly SerializerInterface $publicKeyCredentialLoader,
private readonly AuthenticatorAttestationResponseValidator $attestationResponseValidator,
private readonly PublicKeyCredentialSourceRepositoryInterface $credentialSourceRepository,
private readonly OptionsStorage $optionStorage,
private readonly SuccessHandler $successHandler,
private readonly FailureHandler|AuthenticationFailureHandlerInterface $failureHandler,
private SerializerInterface $publicKeyCredentialLoader,
private AuthenticatorAttestationResponseValidator $attestationResponseValidator,
private PublicKeyCredentialSourceRepositoryInterface $credentialSourceRepository,
private OptionsStorage $optionStorage,
private SuccessHandler $successHandler,
private FailureHandler|AuthenticationFailureHandlerInterface $failureHandler,
) {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@
use function count;
use function is_array;

final class ProfileBasedCreationOptionsBuilder implements PublicKeyCredentialCreationOptionsBuilder
final readonly class ProfileBasedCreationOptionsBuilder implements PublicKeyCredentialCreationOptionsBuilder
{
public function __construct(
private readonly SerializerInterface $serializer,
private readonly ValidatorInterface $validator,
private readonly PublicKeyCredentialSourceRepositoryInterface $credentialSourceRepository,
private readonly PublicKeyCredentialCreationOptionsFactory $publicKeyCredentialCreationOptionsFactory,
private readonly string $profile,
private SerializerInterface $serializer,
private ValidatorInterface $validator,
private PublicKeyCredentialSourceRepositoryInterface $credentialSourceRepository,
private PublicKeyCredentialCreationOptionsFactory $publicKeyCredentialCreationOptionsFactory,
private string $profile,
) {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,16 @@
use function count;
use function is_array;

final class ProfileBasedRequestOptionsBuilder implements PublicKeyCredentialRequestOptionsBuilder
final readonly class ProfileBasedRequestOptionsBuilder implements PublicKeyCredentialRequestOptionsBuilder
{
public function __construct(
private readonly SerializerInterface $serializer,
private readonly ValidatorInterface $validator,
private readonly PublicKeyCredentialUserEntityRepositoryInterface $userEntityRepository,
private readonly PublicKeyCredentialSourceRepositoryInterface $credentialSourceRepository,
private readonly PublicKeyCredentialRequestOptionsFactory $publicKeyCredentialRequestOptionsFactory,
private readonly string $profile,
private readonly null|FakeCredentialGenerator $fakeCredentialGenerator = null,
private SerializerInterface $serializer,
private ValidatorInterface $validator,
private PublicKeyCredentialUserEntityRepositoryInterface $userEntityRepository,
private PublicKeyCredentialSourceRepositoryInterface $credentialSourceRepository,
private PublicKeyCredentialRequestOptionsFactory $publicKeyCredentialRequestOptionsFactory,
private string $profile,
private null|FakeCredentialGenerator $fakeCredentialGenerator = null,
) {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

final readonly class AttestationStatementSupportCompilerPass implements CompilerPassInterface
{
public const string TAG = 'webauthn_attestation_statement_support';
public const TAG = 'webauthn_attestation_statement_support';

public function process(ContainerBuilder $container): void
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

final readonly class CoseAlgorithmCompilerPass implements CompilerPassInterface
{
public const string TAG = 'webauthn_cose_algorithm';
public const TAG = 'webauthn_cose_algorithm';

public function process(ContainerBuilder $container): void
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

final readonly class DynamicRouteCompilerPass implements CompilerPassInterface
{
public const string TAG = 'webauthn_controller';
public const TAG = 'webauthn_controller';

public function process(ContainerBuilder $container): void
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

final readonly class EventDispatcherSetterCompilerPass implements CompilerPassInterface
{
public const string TAG = 'webauthn_can_dispatch_events';
public const TAG = 'webauthn_can_dispatch_events';

public function process(ContainerBuilder $container): void
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

final readonly class ExtensionOutputCheckerCompilerPass implements CompilerPassInterface
{
public const string TAG = 'webauthn_extension_output_checker';
public const TAG = 'webauthn_extension_output_checker';

public function process(ContainerBuilder $container): void
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

final readonly class LoggerSetterCompilerPass implements CompilerPassInterface
{
public const string TAG = 'webauthn_can_log_data';
public const TAG = 'webauthn_can_log_data';

public function process(ContainerBuilder $container): void
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,49 +42,49 @@

final readonly class WebauthnFactory implements FirewallListenerFactoryInterface, AuthenticatorFactoryInterface
{
public const string AUTHENTICATION_PROVIDER_KEY = 'webauthn';
public const AUTHENTICATION_PROVIDER_KEY = 'webauthn';

public const string AUTHENTICATOR_ID_PREFIX = 'security.authenticator.webauthn.';
public const AUTHENTICATOR_ID_PREFIX = 'security.authenticator.webauthn.';

public const string AUTHENTICATOR_DEFINITION_ID = 'webauthn.security.authenticator';
public const AUTHENTICATOR_DEFINITION_ID = 'webauthn.security.authenticator';

public const string DEFAULT_SESSION_STORAGE_SERVICE = SessionStorage::class;
public const DEFAULT_SESSION_STORAGE_SERVICE = SessionStorage::class;

public const string DEFAULT_SUCCESS_HANDLER_SERVICE = DefaultSuccessHandler::class;
public const DEFAULT_SUCCESS_HANDLER_SERVICE = DefaultSuccessHandler::class;

public const string DEFAULT_FAILURE_HANDLER_SERVICE = DefaultFailureHandler::class;
public const DEFAULT_FAILURE_HANDLER_SERVICE = DefaultFailureHandler::class;

public const string DEFAULT_LOGIN_OPTIONS_METHOD = Request::METHOD_POST;
public const DEFAULT_LOGIN_OPTIONS_METHOD = Request::METHOD_POST;

public const string DEFAULT_LOGIN_OPTIONS_PATH = '/login/options';
public const DEFAULT_LOGIN_OPTIONS_PATH = '/login/options';

public const string DEFAULT_LOGIN_RESULT_METHOD = Request::METHOD_POST;
public const DEFAULT_LOGIN_RESULT_METHOD = Request::METHOD_POST;

public const string DEFAULT_LOGIN_RESULT_PATH = '/login';
public const DEFAULT_LOGIN_RESULT_PATH = '/login';

public const string DEFAULT_REQUEST_OPTIONS_HANDLER_SERVICE = DefaultRequestOptionsHandler::class;
public const DEFAULT_REQUEST_OPTIONS_HANDLER_SERVICE = DefaultRequestOptionsHandler::class;

public const string DEFAULT_REGISTER_OPTIONS_METHOD = Request::METHOD_POST;
public const DEFAULT_REGISTER_OPTIONS_METHOD = Request::METHOD_POST;

public const string DEFAULT_REGISTER_OPTIONS_PATH = '/register/options';
public const DEFAULT_REGISTER_OPTIONS_PATH = '/register/options';

public const string DEFAULT_REGISTER_RESULT_METHOD = Request::METHOD_POST;
public const DEFAULT_REGISTER_RESULT_METHOD = Request::METHOD_POST;

public const string DEFAULT_REGISTER_RESULT_PATH = '/register';
public const DEFAULT_REGISTER_RESULT_PATH = '/register';

public const string DEFAULT_CREATION_OPTIONS_HANDLER_SERVICE = DefaultCreationOptionsHandler::class;
public const DEFAULT_CREATION_OPTIONS_HANDLER_SERVICE = DefaultCreationOptionsHandler::class;

public const string FIREWALL_CONFIG_ID_PREFIX = 'security.firewall_config.webauthn.';
public const FIREWALL_CONFIG_ID_PREFIX = 'security.firewall_config.webauthn.';

public const string AUTHENTICATOR_ATTESTATION_RESPONSE_VALIDATOR_ID_PREFIX = 'security.authenticator_attestation_response_validator.webauthn.';
public const AUTHENTICATOR_ATTESTATION_RESPONSE_VALIDATOR_ID_PREFIX = 'security.authenticator_attestation_response_validator.webauthn.';

public const string AUTHENTICATOR_ASSERTION_RESPONSE_VALIDATOR_ID_PREFIX = 'security.authenticator_assertion_response_validator.webauthn.';
public const AUTHENTICATOR_ASSERTION_RESPONSE_VALIDATOR_ID_PREFIX = 'security.authenticator_assertion_response_validator.webauthn.';

public const string CEREMONY_STEP_MANAGER_ID_PREFIX = 'security.ceremony_step_manager.webauthn.';
public const CEREMONY_STEP_MANAGER_ID_PREFIX = 'security.ceremony_step_manager.webauthn.';

public const string FIREWALL_CONFIG_DEFINITION_ID = 'webauthn.security.firewall_config';
public const FIREWALL_CONFIG_DEFINITION_ID = 'webauthn.security.firewall_config';

private const int PRIORITY = 0;
private const PRIORITY = 0;

public function __construct(
private WebauthnServicesFactory $servicesFactory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

final class WebauthnAuthenticationEvent extends BadCredentialsException
{
private const string MESSAGE_KEY = 'invalid';
private const MESSAGE_KEY = 'invalid';

public function getMessageKey(): string
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

interface WebauthnAuthenticationEvents
{
public const string FAILURE = 'failure';
public const FAILURE = 'failure';

public const string SUCCESS = 'success';
public const SUCCESS = 'success';
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

final readonly class IsUserPresentVoter implements VoterInterface
{
public const string IS_USER_PRESENT = 'IS_USER_PRESENT';
public const IS_USER_PRESENT = 'IS_USER_PRESENT';

public function vote(TokenInterface $token, mixed $subject, array $attributes): int
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

final readonly class IsUserVerifiedVoter implements VoterInterface
{
public const string IS_USER_VERIFIED = 'IS_USER_VERIFIED';
public const IS_USER_VERIFIED = 'IS_USER_VERIFIED';

public function vote(TokenInterface $token, mixed $subject, array $attributes): int
{
Expand Down
6 changes: 3 additions & 3 deletions src/symfony/src/Security/Guesser/CurrentUserEntityGuesser.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
use Webauthn\Bundle\Repository\PublicKeyCredentialUserEntityRepositoryInterface;
use Webauthn\PublicKeyCredentialUserEntity;

final class CurrentUserEntityGuesser implements UserEntityGuesser
final readonly class CurrentUserEntityGuesser implements UserEntityGuesser
{
public function __construct(
private readonly TokenStorageInterface $tokenStorage,
private readonly PublicKeyCredentialUserEntityRepositoryInterface $userEntityRepository
private TokenStorageInterface $tokenStorage,
private PublicKeyCredentialUserEntityRepositoryInterface $userEntityRepository
) {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
use Webauthn\PublicKeyCredentialUserEntity;
use function count;

final class RequestBodyUserEntityGuesser implements UserEntityGuesser
final readonly class RequestBodyUserEntityGuesser implements UserEntityGuesser
{
public function __construct(
private readonly SerializerInterface $serializer,
private readonly ValidatorInterface $validator,
private readonly PublicKeyCredentialUserEntityRepositoryInterface $userEntityRepository,
private SerializerInterface $serializer,
private ValidatorInterface $validator,
private PublicKeyCredentialUserEntityRepositoryInterface $userEntityRepository,
) {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
use Webauthn\PublicKeyCredentialUserEntity;
use function is_array;

final class DefaultCreationOptionsHandler implements CreationOptionsHandler
final readonly class DefaultCreationOptionsHandler implements CreationOptionsHandler
{
public function __construct(
private readonly NormalizerInterface $normalizer
private NormalizerInterface $normalizer
) {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
use Webauthn\PublicKeyCredentialUserEntity;
use function is_array;

final class DefaultRequestOptionsHandler implements RequestOptionsHandler
final readonly class DefaultRequestOptionsHandler implements RequestOptionsHandler
{
public function __construct(
private readonly NormalizerInterface $normalizer
private NormalizerInterface $normalizer
) {
}

Expand Down
2 changes: 1 addition & 1 deletion src/symfony/src/Security/Storage/CacheStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

final readonly class CacheStorage implements OptionsStorage
{
private const string CACHE_PARAMETER = 'WEBAUTHN_PUBLIC_KEY_OPTIONS';
private const CACHE_PARAMETER = 'WEBAUTHN_PUBLIC_KEY_OPTIONS';

public function __construct(
private CacheItemPoolInterface $cache
Expand Down
6 changes: 3 additions & 3 deletions src/symfony/src/Security/Storage/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
use Webauthn\PublicKeyCredentialOptions;
use Webauthn\PublicKeyCredentialUserEntity;

final class Item
final readonly class Item
{
public function __construct(
private readonly PublicKeyCredentialOptions $publicKeyCredentialOptions,
private readonly ?PublicKeyCredentialUserEntity $publicKeyCredentialUserEntity
private PublicKeyCredentialOptions $publicKeyCredentialOptions,
private ?PublicKeyCredentialUserEntity $publicKeyCredentialUserEntity
) {
}

Expand Down
2 changes: 1 addition & 1 deletion src/symfony/src/Security/Storage/SessionStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

final readonly class SessionStorage implements OptionsStorage
{
private const string SESSION_PARAMETER = 'WEBAUTHN_PUBLIC_KEY_OPTIONS';
private const SESSION_PARAMETER = 'WEBAUTHN_PUBLIC_KEY_OPTIONS';

public function __construct(
private RequestStack $requestStack
Expand Down
Loading

0 comments on commit 0eab3e4

Please sign in to comment.