-
Notifications
You must be signed in to change notification settings - Fork 107
#202 Add rule to prevent final constructors in doctrine entities #395
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
Conversation
The failing checks don't seem to be related to the changes of this PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, the rule needs to be registered in rules.neon, but only for bleedingEdge.
Thanks.
throw new ShouldNotHappenException(); | ||
} | ||
|
||
return [sprintf( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use RuleErrorBuilder here.
return []; | ||
} | ||
|
||
$classReflection = $scope->getClassReflection(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're reporting in all classes, not just entities.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I'm correct, this should work now only for entities. I've taken this code from EntityNotFinalRule
for the detection, if the class is an entity
if ($this->objectMetadataResolver->isTransient($classReflection->getName())) {
return [];
}
$metadata = $this->objectMetadataResolver->getClassMetadata($classReflection->getName());
if ($metadata !== null && $metadata->isEmbeddedClass === true) {
return [];
}
Hi, sorry for the delay :) |
rules.neon
Outdated
@@ -23,10 +23,13 @@ rules: | |||
- PHPStan\Rules\Doctrine\ORM\DqlRule | |||
- PHPStan\Rules\Doctrine\ORM\RepositoryMethodCallRule | |||
- PHPStan\Rules\Doctrine\ORM\EntityNotFinalRule | |||
- PHPStan\Rules\Doctrine\ORM\EntityConstructorNotFinalRule |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need to remove it from the rules
section.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, okay. I removed it there. :)
Thank you! |
This fixes #202.
What do you think about that?