Skip to content
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

Signature of abstract methods defined in traits is checked against the implementing class method in php 8+ #1712

Closed
1 task
lee-van-oetz opened this issue May 17, 2024 · 3 comments

Comments

@lee-van-oetz
Copy link

lee-van-oetz commented May 17, 2024

Is your feature request related to a problem?

I am trying to upgrade from PHP 7.4 to PHP 8.x and have used this package to check the code -- just warnings reported, no errors, but after upgrade, I am indeed getting errors, most prevalent for me is
From https://www.php.net/manual/en/migration80.incompatible.php:

The signature of abstract methods defined in traits is now checked against the implementing class method:

Describe the solution you'd like

I'm not too sure about inner workings of phpcs. I would like this issue to be reported ofc :) I can try to add this, but I would probably need some guidance.

  • I intend to create a pull request to implement this feature.
@jrfnl
Copy link
Member

jrfnl commented May 17, 2024

@lee-van-oetz Thank you for reporting this. I believe your issue is related to this RFC.

Unfortunately, this is not something which can reliably be checked with PHPCompatibility as, by its nature, PHP_CodeSniffer only has access to the current file.

The only case in which this could reliably be checked by PHPCompatibility, is when the interface/trait and the class implementing the interface/using the trait would be declared in the same file, however, as it is uncommon to have multiple OO structures defined in the same file as the fast majority of PHP projects adhere to PSR-4, this would be an edge case, which makes it not worth the time investment to write the sniff.

While PHPCompatibility can find a lot of things, you will also need good tests when upgrading and these signature issues would be flagged via a failing test suite.

Suggest: close.

@lee-van-oetz
Copy link
Author

Thanks for explaning.

@MarkMaldaba
Copy link
Contributor

@lee-van-oetz You might be interested in PHPStan, which I believe should catch this issue. PHPStan also uses static analysis, but works at a project level rather than a file level, so it knows about parent classes/traits/etc. It isn't a compatibility-testing tool, but it does check for a number of code-correctness issues, and so it should report on this (and if not, I'm sure it's on the roadmap).

Project website: https://phpstan.org/

I use PHPCompatibility and PHPStan on all my projects, and both tools are excellent at what they do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants