-
Notifications
You must be signed in to change notification settings - Fork 548
Support @readonly phpdoc
#1295
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
Support @readonly phpdoc
#1295
Conversation
|
I had a discussion in the past about implementing it. These are the main directions, which ondrey gave me:
I don't know whether this information is still valid as is... just to let you know. |
9bf9ec8 to
30e6f46
Compare
8372aaa to
60d6be2
Compare
f070817 to
1812e67
Compare
|
I think for this to work, we need a new method
I really want to separate the rules for "this is native readonly keyword" and "this is done by PHPDoc" as they can diverge over time. I don't want the current |
1812e67 to
770c241
Compare
|
I separated native and phpdoc readonly, as requested, and for simplicity I chose to adapt the current existing rules. I also added new test sets that are basically duplicates of the current ones minus PHP 7.4+ features (native property types, native readonly, enums). Good idea with the separation for sure, see #1295 (comment) where I decided to not add phpdoc readonly support for What do you think, is this going in the right direction? |
553d42b to
1db1656
Compare
|
Sorry for my impatience, I hate that xD |
Let me assure you that you can keep calm because it mostly doesn't matter :)
|
ondrejmirtes
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
where I decided to not add phpdoc readonly support for MissingReadOnlyPropertyAssignRule and UninitializedPropertyRule
With my proposal of separate rules, this should probably be done, right?
1db1656 to
5bef33f
Compare
…rules to bleeding edge, use consistent naming for methods and props
5bef33f to
82247bf
Compare
ondrejmirtes
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really nice! Almost there :)
src/Rules/Properties/MissingReadOnlyByPhpDocPropertyAssignRule.php
Outdated
Show resolved
Hide resolved
src/Rules/Properties/MissingReadOnlyByPhpDocPropertyAssignRule.php
Outdated
Show resolved
Hide resolved
…ence to the non-phpdoc rules
|
Thank you! |
|
Can you please send an update to this page @herndlm? https://phpstan.org/writing-php-code/phpdocs-basics Thank you! |
|
I'll update the docs tomorrow, have fun in Verona! |
Same as psalm does it, see https://psalm.dev/docs/annotating_code/supported_annotations/#psalm-readonly-and-readonly
I guess this would be very useful for pre PHP 8.1 and/or to safely enable native
readonly. But I think this is also the first step in the direction of a@phpstan-immutablephpdoc on class level, but that's a different thing.If I understood things right this should not interfere with some of the other rules that are related to nativeirrelevant, because the phpdoc rules were separated later on :)readonlybecause the phpdoc is not used in https://github.com/phpstan/phpstan-src/blob/1.6.7/src/Node/ClassPropertyNode.php#L77. I added tests to check that where it made sense to me.Refs: phpstan/phpstan#4082