I wrote the following lines of code:
$this->validate($group);
$this->em->persist($group);
$this->em->flush();
Method "validate" will throw an exception if $group is not valid. The issue is, it seems kind of "fragile" as if other developer would come and try to refactor, maybe he would accidently move the validate method and entity manager would save the object into the database without validating it.
Do you think the following lines of code are better or am I just overthinking it?
$validGroup = $this->validate($group);
$this->em->persist($validGroup);
$this->em->flush();
Aucun commentaire:
Enregistrer un commentaire