-
-
Notifications
You must be signed in to change notification settings - Fork 671
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
Incorrect behavior of RemoveUnusedPrivateMethodRector #6613
Comments
Thank you for your report and demo link! Could you send a failing test case in a pull-request, so we have it covered in Rector? |
# Failing Test for RemoveUnusedPrivateMethodRector Based on https://getrector.org/demo/1ebf50d7-992f-63ba-9a8a-bd39c81b9232 refs: rectorphp/rector#6613
* Add failing test fixture for ReturnTypeFromReturnNewRector # Failing Test for ReturnTypeFromReturnNewRector Based on https://getrector.org/demo/1ebef269-093c-6afe-9c29-afdc8959befb refs rectorphp/rector#6595 * Add failing test fixture for RemoveUnusedPrivateMethodRector # Failing Test for RemoveUnusedPrivateMethodRector Based on https://getrector.org/demo/1ebf50d7-992f-63ba-9a8a-bd39c81b9232 refs: rectorphp/rector#6613 * fix test case skip_abstract_private_method_in_trait.php.inc * remove file from previous PR * fix fixture by moving namespace to top * import TraitUse * use AstResolver * added test case to check if non-abstract private methods are considered * refac: moved "is used" checks into it's own class to reduce class complexity * rename constructor arg to represent class name
@bertrandjamin the issue is now fixed. Given that the abstract private function is PHP 8.0+ we should probably consider writing a downgrade rector for that, since I didn't find any in the PHP 8.0 downgrades., right @TomasVotruba? |
@Bl00D4NGEL thanks ! I let you or @TomasVotruba close the issue according to his answer. |
@Bl00D4NGEL after reading your PR I have a question about https://github.com/Bl00D4NGEL/rector-src/blob/06b4aef9aa4607df84ea7f37fa641809ac0b503c/rules-tests/DeadCode/Rector/ClassMethod/RemoveUnusedPrivateMethodRector/Fixture/remove_if_method_non_abstract_private_in_trait.php.inc Given the php documentation (https://www.php.net/manual/en/language.oop5.traits.php#language.oop5.traits.precedence) a method in the class can override the one created in the trait. Am I missing something ? |
@bertrandjamin you would be correct. I tested it in the PHPSandbox: http://sandbox.onlinephpfunctions.com/code/fa84c5aaa7ca8433d7b7e486a82bc678f21aaac7 and it seems like you actually can overwrite the private function, my bad there. |
@Bl00D4NGEL I think you can fix it here, as it's closely related. |
It seems already fixed, closing. |
Bug Report
The rule
RemoveUnusedPrivateMethodRector
don't handle correctly abstract private functions in a trait.ℹ️ This a new PHP8 capability : https://www.php.net/manual/en/language.oop5.traits.php#language.oop5.traits.abstract.
Minimal PHP Code Causing Issue
See https://getrector.org/demo/1ebf50d7-992f-63ba-9a8a-bd39c81b9232
Responsible rules
RemoveUnusedPrivateMethodRector
Expected Behavior
As the abstract
privateMethod
is used inpublicMethod
the rule should not remove theprivateMethod
implementation inMyClass
Thanks for your help
The text was updated successfully, but these errors were encountered: