Skip to content

Implement FinalPrivateConstantRule #3838

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

Merged
merged 3 commits into from
Feb 26, 2025
Merged

Conversation

staabm
Copy link
Contributor

@staabm staabm commented Feb 26, 2025

as requested in #3830 (review)

{
$this->analyse([__DIR__ . '/data/final-private-const.php'], [
[
'Private constant FinalPrivateConstants\User::FINAL_PRIVATE() cannot be final as it is not visible to other classes.',
Copy link
Contributor Author

Choose a reason for hiding this comment

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

used the error message from https://3v4l.org/oBYII

$errors = [];
foreach ($node->consts as $classConstNode) {
$errors[] = RuleErrorBuilder::message(sprintf(
'Private constant %s::%s() cannot be final as it is not visible to other classes.',
Copy link
Member

Choose a reason for hiding this comment

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

Please follow the method wording: Private method HelloWorld::sayHello() cannot be final as it is never overridden by other classes.

'Private constant %s::%s() cannot be final as it is never overridden by other classes.',
$classReflection->getDisplayName(),
$classConstNode->name->name,
))->identifier('classConstant.finalPrivate')->build();
Copy link
Member

Choose a reason for hiding this comment

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

should be non-ignorable

@ondrejmirtes ondrejmirtes merged commit 595b186 into phpstan:2.1.x Feb 26, 2025
417 of 419 checks passed
@ondrejmirtes
Copy link
Member

Thank you!

@staabm staabm deleted the final-private branch February 26, 2025 16:46
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.

None yet

2 participants