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

feat: Introduce config option for standardized null in typehints #7860

Conversation

kayw-geek
Copy link
Contributor

@kayw-geek kayw-geek commented Mar 1, 2024

This PR introduces a new configuration option force_nullable_for_default_null to nullable_type_declaration_for_default_null_value rule, aimed at enhancing the consistency and clarity of typehints across our codebase.

By automatically converting optional types to explicit union types with null, we enable a more standardized approach to handling nullable type declarations.

Key Benefits:

  • Consistency: Ensures a uniform standard across the codebase for representing nullable types, making the code more predictable and easier to read.
  • Clarity: Expanding ?Type to Type|null makes the nullable aspect of the typehints explicit, improving readability, and comprehension for developers.
  • Flexibility: With this configurable option, developers can tailor the behavior to their specific project needs, choosing between implicit optional types or explicit nullability.

Implementation Details:
The configuration option force_nullable_for_default_null can be toggled to automatically modify the typehints during the PHPCSFixer fix process. When enabled, it ensures that all parameters with a default null value explicitly include null in their type declaration, transforming ?Type hints to Type|null for clearer and more explicit code.

@kayw-geek kayw-geek changed the title Introduce config option for standardized null in typehints feat: Introduce config option for standardized null in typehints Mar 1, 2024
@kayw-geek kayw-geek marked this pull request as draft March 1, 2024 08:11
@kayw-geek kayw-geek force-pushed the feature/add-configurable-to-nullable-type-declaration-for-default-null-value branch from 431c2b8 to fd7018a Compare March 1, 2024 08:36
@kayw-geek kayw-geek marked this pull request as ready for review March 1, 2024 08:36
Copy link
Member

@Wirone Wirone left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Standardisation of nullable type declaration is handled with... nullable_type_declaration fixer 😉. There's no need for supporting this in nullable_type_declaration_for_default_null_value, which has different responsibility.

To achieve what this PR aims for you just need to configure nullable_type_declaration_for_default_null_value with use_nullable_type_declaration=true (default) and if you prefer union type you have to also add nullable_type_declaration with syntax=union.

Unfortunately it looks like we need to close this without merging.

@kayw-geek kayw-geek closed this Mar 1, 2024
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.

None yet

2 participants