-
Notifications
You must be signed in to change notification settings - Fork 19
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 deprecated magic __toString() in echo statement #37
base: 1.1.x
Are you sure you want to change the base?
Conversation
tests/Rules/Deprecations/data/echo-deprecated-magic-method-tostring.php
Outdated
Show resolved
Hide resolved
if (!$methodReflection->isDeprecated()->yes()) { | ||
continue; | ||
} | ||
|
||
$description = $methodReflection->getDeprecatedDescription(); | ||
if ($description === null) { | ||
$messages[] = sprintf( | ||
'Call to deprecated method %s() of class %s.', | ||
$methodReflection->getName(), | ||
$methodReflection->getDeclaringClass()->getName() | ||
); | ||
} else { | ||
$messages[] = sprintf( | ||
"Call to deprecated method %s() of class %s:\n%s", | ||
$methodReflection->getName(), | ||
$methodReflection->getDeclaringClass()->getName(), | ||
$description | ||
); | ||
} |
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.
most of this code is inspired by CallToDeprecatedMethodRule
tests/Rules/Deprecations/data/echo-deprecated-magic-method-tostring.php
Outdated
Show resolved
Hide resolved
Hi, this is rather incomplete and does not have rules for other situations. What I recommend in your situation:
|
Thx for your feedback. I am not sure how I should take it. I am aware there are a lot of more things to take care of, but just want to get in contact early, since the very basic case which is important to me is already covered. Was your suggestion about how I should proceed to get this rule into shape so you might consider merging it, or was your intention to give me a hint of how I should handle a possible deprecated Thanks again |
I want ahead and added more coverage for more complex expressions. In case someone knows a expression I am missing feel free to sent me an example. |
* @param Scope $scope | ||
* @param string[] $messages | ||
*/ | ||
private function deepCheckExpr(Node\Expr $expr, Scope $scope, array &$messages): void |
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.
As a followup step, I would extract this logic into a helper and add a separate rule for Print.
Additionally a Rule could be added for the string-concat case
…e with bleeding edge switch
hey ondrey, thx again for your feedback. I tried to incorporate what I have understood so far. I have extracted a new does this look good to you? |
with this change phpstan is able to detect cases, where object values are used in
echo
statements and implicitly call a magic and deprecated__toString
method.In case this new rule gets accepted, I would be willing to implement the same for the
print
statement.refs phpstan/phpstan#4899