phpstan-deprecation-rules
phpstan-deprecation-rules copied to clipboard
Allow flagging a node with an "ignore deprecation" attribute via NodeVisitorAbstract to skip deprecation errors
A common pattern is to use if/else
statements for backward compatibility with deprecated methods to provide support between versions before the deprecation was introduced and to provide a fix for after.
One example can be found here: https://github.com/mglaman/phpstan-drupal/issues/461
if (method_exists($this->moduleHandler, 'invokeAllWIth')) {
// use the new invokeAllWIth method
} else {
// use legacy getImplementations method
}
The easiest fix is to add // @phpstan-ignore-next-line
whenever using backward compatible code. But I was trying to see if it'd be possible to use a node visitor to detect the if/else
to set an attribute flag. Which it does seem possible (whether it is right or wrong.)
Would this package accept a check of checking for an attribute to imply a deprecated scope?
$node->getAttribute('inDeprecatedScope', false)
I don't know how other frameworks are handling this kind of bridge, I need to look.