implemented TypedPropertyFromStrictConstructorReadonlyClassRector#4552
implemented TypedPropertyFromStrictConstructorReadonlyClassRector#4552TomasVotruba merged 17 commits intorectorphp:mainfrom
Conversation
| private function skipPublicProperty(Node\Stmt\Property $property, ClassReflection $classReflection, Scope $scope): bool | ||
| { | ||
| if ($property->isPublic()) { | ||
| $isReadOnlyByPhpdoc = false; |
There was a problem hiding this comment.
we only care about readonly phpdoc, because native readonly classes cannot have non-typed-properties by definition
|
|
||
| namespace Rector\Tests\TypeDeclaration\Rector\Property\TypedPropertyFromStrictConstructorRector\Fixture; | ||
|
|
||
| class ReadonlyPublicProperty |
There was a problem hiding this comment.
this test-case is not super realistic, but since the readonly flag is only enforced via static analysis its a case which can happen
|
I think its worth new rule instead to ease improve/skip the rule. More and more tweak on docblock is harder to patch when found a bug. |
…yFromStrictConstructorRector.php
|
separated the immutable handling in a new rule |
|
This is very nice, thank you 👏 |
|
I'm looking into more complex rules spotted in #5025. It seems this one is going back to the doblock-based logic we try to avoid from. The Rector upgrade path is based on PHP native features, so the motivation is to rise the PHP version, instead of "backporting" features using markers. Saying that, I'll deprecate this rule and it should be made private, if needed, not to promote docblock based logic. My mistake this got through the review :) 🙏 |
In TypedPropertyFromStrictConstructorRector before this PR we skipped over public properties.
after this PR, we infer native types in
@immutablephpdoc typed classes.the assumption is, that no external code should exist which writes into the public properties
Feature description https://psalm.dev/docs/annotating_code/supported_annotations/#psalm-readonly-and-readonly
PHPStan impl phpstan/phpstan-src#1295