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

[PHP8.2] Support for readonly classes #6604

Closed
Wirone opened this issue Sep 1, 2022 · 9 comments · Fixed by #6745
Closed

[PHP8.2] Support for readonly classes #6604

Wirone opened this issue Sep 1, 2022 · 9 comments · Fixed by #6745
Labels
kind/feature request topic/PHP8.2 Related to features available in PHP 8.2+

Comments

@Wirone
Copy link
Member

Wirone commented Sep 1, 2022

The goal of this task is to provide support for readonly classes. New class-level keyword must not break any fixers and should be supported only for PHP 8.2+

@kubawerlos
Copy link
Contributor

Would be nice to have indeed, can you propose a PR for it, please?

@SpacePossum
Copy link
Contributor

SpacePossum commented Sep 2, 2022

We should update the tokenizer to make a custom CT::CLASS_READONLY token for this and than make PR's to update the rules that need it.

Maybe new rules:

  • if a class has only readonly properties, make the class itself readonly, remove the readonly keyword from the properties
  • if a class is readonly, remove the readonly keyword from the properties

@SpacePossum
Copy link
Contributor

Just to double check, but anonymous classes cannot be readonly right? (not sure why TBH, didn't find anything on the subject)

@keradus keradus added the topic/PHP8.2 Related to features available in PHP 8.2+ label Sep 8, 2022
@jaikdean
Copy link

jaikdean commented Jan 3, 2023

Just to double check, but anonymous classes cannot be readonly right? (not sure why TBH, didn't find anything on the subject)

Correct, anonymous classes cannot be readonly.

@BenMorel
Copy link
Contributor

BenMorel commented Jan 6, 2023

2 points:

-> It would be nice to provide a fixer to remove readonly from properties of readonly classes.

@alfredbez
Copy link

Looks like these two examples are valid:

readonly final class Foo {}
final readonly class Foo {}

But when I try to apply the final_class rule on that code it breaks:

Files that were not fixed due to errors reported during linting after fixing:
   1) /home/runner/work/php-cs-fixer-8.2/php-cs-fixer-8.2/Foo.php

Here's a small repo to reproduce the problem:

I did not test this against the PR from @mateuszsip

@SpacePossum
Copy link
Contributor

it is all here #6624 , if anyone is interested in finishing it

@Wirone
Copy link
Member Author

Wirone commented Jan 9, 2023

@alfredbez could you verify #6745 against your reproducer and check if it works properly?

@alfredbez
Copy link

alfredbez commented Jan 9, 2023

This bug is solved with the change from the PR: CI output 🎉

(commit)


I also tried to change in #6744 but it does not work for the same reason.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/feature request topic/PHP8.2 Related to features available in PHP 8.2+
Projects
None yet
7 participants