Skip to content

Implement FinalPrivateConstantRule#3838

Merged
ondrejmirtes merged 3 commits intophpstan:2.1.xfrom
staabm:final-private
Feb 26, 2025
Merged

Implement FinalPrivateConstantRule#3838
ondrejmirtes merged 3 commits intophpstan:2.1.xfrom
staabm:final-private

Conversation

@staabm
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

2 participants