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
[FR] Detect use of deprecated class/object methods #1300
Comments
@sarfrazeteam Well, the simple answer is: by writing a sniff to detect deprecated and removed class methods. The reason such a sniff does not exist is that for accurate detection of methods on classes, we'd need a way to resolve an object variable to its class and as the code is tokenized, not run, that's nowhere near as easy as it sounds. Some code samples of things such a sniff would need to be able to handle: $obj = new ReflectionParameter();
$obj->getClass();
class Foo extends ReflectionParameter {
function bar() {
$this->getClass();
}
}
function foo(ReflectionParameter $obj) {
$obj->getClass();
} Note: these code samples are still the relatively "easy" ones, i.e. the cases which may be detectable... |
So that simply means we cannot rely completely on PHPCompatibility as of now when checking things before upgrading ? |
@sarfrazeteam You never could and never will be able to in the future either. Static analysis tools, no matter how good, are never a replacement for having unit tests. At the same time, unit tests are only as reliable as the tests are good and complete (which in most cases means: not that good, nor complete). Using both - static analysis AND tests - will give you a good starting point to assess your code's readiness for a new PHP version. |
Right, makes sense, thanks for the explanation |
I am trying to check for errors via phpcs and PHPCompatibility standard on a laravel project, here is the command:
The command works fine. However, I am supposed to receive following error but I am not:
Deprecated: Method ReflectionParameter::getClass() is deprecated in somefile.php on line 838
The actual code where PHP8 fails but PHPCS does not inform:
The reason PHPCompatibility standard should tell me about this error is that when I try to run my app in PHP 8 I get above error, however PHPCS with PHPCompatibility does not report above error.
Any idea how can I make PHPCompatibility report above error ?
The text was updated successfully, but these errors were encountered: