#202 Add rule to prevent final constructors in doctrine entities#395
#202 Add rule to prevent final constructors in doctrine entities#395ondrejmirtes merged 3 commits intophpstan:1.3.xfrom LeoVie:1.3.x
Conversation
|
The failing checks don't seem to be related to the changes of this PR. |
ondrejmirtes
left a comment
There was a problem hiding this comment.
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.
Please use RuleErrorBuilder here.
| return []; | ||
| } | ||
|
|
||
| $classReflection = $scope->getClassReflection(); |
There was a problem hiding this comment.
You're reporting in all classes, not just entities.
There was a problem hiding this comment.
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
| - 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.
You need to remove it from the rules section.
There was a problem hiding this comment.
Ah, okay. I removed it there. :)
|
Thank you! |
This fixes #202.
What do you think about that?