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

Implement ProtectedMethodInFinalClassRule #68

Closed
wants to merge 9 commits into from

Conversation

staabm
Copy link
Contributor

@staabm staabm commented Jun 27, 2023

protected methods in final classes are not very useful. private methods can be analyzed easier and phpstan covers more cases for them.

with this PR, we report a error for these unnecessary protected methods, because when these are reduced to private visibility e.g. phpstan private symbol analytics kicks in and might detect unused private methods.

the same is true for protected properties, and I plan to contribute another rule, in case we agree on this one.

{
}

protected function protectedMethod()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems like there is a ECS style rule which reduces the visibility of the method and therefore destroys the test-case :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

skipped with 4814f0e

@staabm staabm marked this pull request as ready for review June 27, 2023 09:07
@staabm
Copy link
Contributor Author

staabm commented Jun 27, 2023

I think this one is good to go.

@staabm
Copy link
Contributor Author

staabm commented Jun 28, 2023

I think we could the same for final methods in non-final classes.. same rule?

@staabm
Copy link
Contributor Author

staabm commented Jul 8, 2023

@TomasVotruba wdyt?

@staabm
Copy link
Contributor Author

staabm commented Jul 8, 2023

Thinking again about it. Maybe it should even be a rector to reduce visibility instead?

@TomasVotruba
Copy link
Owner

TomasVotruba commented Jul 24, 2023

Hi, I just got in here, thank you for your patience.

While this is useful rule, I think it's difference scope. Also as you said, already handled in Rector in "privatization" set that makes sure the visiblity of class elements is as low as possible.

This package focuses only on reporting public class elements, nothing more.

Also potential for own package, but I don't think it's worth as already handled in Rector/ECS :)

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

Successfully merging this pull request may close these issues.

2 participants