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

nullable_type_declaration_for_default_null_value should not fix readonly constructor promoted properties if set to false #6239

Closed
devmrcl opened this issue Jan 14, 2022 · 1 comment · Fixed by #6265
Labels

Comments

@devmrcl
Copy link

devmrcl commented Jan 14, 2022

Bug report

Rule

'nullable_type_declaration_for_default_null_value' => ['use_nullable_type_declaration' => false]

Description

Latest version 3.5 "fixes" readonly promoted properties with the given rule.
Rule should not touch the code like with non-readonly promoted properties.

Code snippet that reproduces the problem

class SomeClass
{
   public function __construct(
      public ?string $string = null,
      public readonly ?string $readonlyString = null,
   ){}
}

Diff output

public function __construct(
         public ?string $string = null,
-        public readonly ?string $readonlyString = null,
+        public readonly string $readonlyString = null,
)

Possible fix

Add check for T_READONLY

https://github.com/FriendsOfPHP/PHP-CS-Fixer/blob/333f15e07c866e33e2765e84ba1e0b88e6a3af3b/src/Fixer/FunctionNotation/NullableTypeDeclarationForDefaultNullValueFixer.php#L139-L152

@SpacePossum
Copy link
Contributor

Thanks for reporting @devmrcl , proposed fix is here #6265 , please review if you want : )

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

Successfully merging a pull request may close this issue.

2 participants