Skip to content
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

Refactor: Use nullable type hints for optional dependencies and param… #1261

Open
wants to merge 1 commit into
base: 3.x
Choose a base branch
from

Conversation

gzim324
Copy link

@gzim324 gzim324 commented Dec 3, 2024

Fix Deprecation Notices in LexikJWTAuthenticationBundle

Summary

This pull request addresses multiple deprecation notices that occur when using the LexikJWTAuthenticationBundle with PHP 8.4. The fixes involve explicitly marking nullable parameters in constructors and methods to comply with PHP 8.4 requirements.

Fixed Issues

  1. JWTAuthenticator::__construct
    Implicitly marking parameter $translator as nullable is deprecated. The parameter is now explicitly marked as ?TranslatorInterface.

  2. JWTAuthenticator::start
    Implicitly marking parameter $authException as nullable is deprecated. The parameter is now explicitly marked as ?AuthenticationException.

  3. JWTManager::__construct
    Implicitly marking parameter $payloadEnrichment as nullable is deprecated. The parameter is now explicitly marked as ?PayloadEnrichmentInterface.

  4. LcobucciJWSProvider::__construct
    Implicitly marking parameter $clock as nullable is deprecated. The parameter is now explicitly marked as ?ClockInterface.

  5. AuthenticationFailureHandler::__construct
    Implicitly marking parameter $translator as nullable is deprecated. The parameter is now explicitly marked as ?TranslatorInterface.

Changes Made

  • Updated JWTAuthenticator to use ?TranslatorInterface and ?AuthenticationException where applicable.
  • Modified AuthenticationFailureHandler to use ?TranslatorInterface in the constructor.
  • Adjusted LcobucciJWSProvider to use ?Clock in the constructor for better nullability support.
  • Updated JWTManager to use ?PayloadEnrichmentInterface for the optional payload enrichment dependency.

Environment

  • PHP Version: 8.4
  • Symfony Version: 7.2
  • LexikJWTAuthenticationBundle Version: 3.1.0
  • PHPUnit: 9.6.21

Additional Context

These changes aim to ensure smooth operation in PHP 8.4 environments by addressing all known deprecation warnings related to nullable parameters.

…eters

Updated constructors and method signatures to explicitly use nullable type hints (?Type) for optional parameters and dependencies. This improves code clarity and ensures alignment with modern PHP type hinting practices.

- Updated JWTAuthenticator to use ?TranslatorInterface and ?AuthenticationException where applicable.
- Modified AuthenticationFailureHandler to use ?TranslatorInterface in the constructor.
- Adjusted LcobucciJWSProvider to use ?Clock in the constructor for better nullability support.
- Updated JWTManager to use ?PayloadEnrichmentInterface for the optional payload enrichment dependency.

These changes improve type safety, readability, and consistency across the codebase.
@maxhelias
Copy link
Contributor

There's already a PR on this topic : #1238

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants