-
Notifications
You must be signed in to change notification settings - Fork 506
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
Readonly properties cannot be unset() #3827
Conversation
This pull request has been marked as ready for review. |
3ee6c73
to
06e46c2
Compare
06e46c2
to
b390edc
Compare
b390edc
to
aa238e2
Compare
adjusted per feedback. thank you. |
} elseif ( | ||
$node instanceof Node\Expr\PropertyFetch | ||
&& $node->name instanceof Node\Identifier | ||
) { |
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.
We have better ways of getting a property reflection from PropertyFetch. Two actually:
- PropertyReflectionFinder. FoundPropertyReflection will even tell you if it's a native one or not.
Scope::getPropertyReflection()
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.
ahh nice.
I was already searching how to know about property hooks so I can implement the error for unsetting a hooked property.
will be a followup PR
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.
I wrote about property hooks here phpstan/phpstan#12337
src/Rules/Variables/UnsetRule.php
Outdated
} | ||
|
||
if ($propertyReflection->isReadOnly() || $propertyReflection->isReadOnlyByPhpDoc()) { | ||
$type = $scope->getType($node->var); |
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.
You don't need to do this, just ask for property declaringClass getDisplayName.
src/Rules/Variables/UnsetRule.php
Outdated
|
||
return RuleErrorBuilder::message( | ||
sprintf( | ||
'Cannot unset %s property %s of %s.', |
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.
Usually we do Foo::$name format.
%s of %s sounds like an ancient text: Yennefer of Vengerberg 😀
31eb5d6
to
71ff1f6
Compare
Perfect, thank you! |
closes phpstan/phpstan#12421