diff --git a/src/Bundle/ChillMainBundle/Form/Type/DataTransformer/ObjectToIdTransformer.php b/src/Bundle/ChillMainBundle/Form/Type/DataTransformer/ObjectToIdTransformer.php index 145ab0441..68f10b9c6 100644 --- a/src/Bundle/ChillMainBundle/Form/Type/DataTransformer/ObjectToIdTransformer.php +++ b/src/Bundle/ChillMainBundle/Form/Type/DataTransformer/ObjectToIdTransformer.php @@ -15,7 +15,7 @@ use Doctrine\ORM\EntityManagerInterface; use Symfony\Component\Form\DataTransformerInterface; use Symfony\Component\Form\Exception\TransformationFailedException; -class ObjectToIdTransformer implements DataTransformerInterface +final class ObjectToIdTransformer implements DataTransformerInterface { private ?string $class; @@ -38,7 +38,7 @@ class ObjectToIdTransformer implements DataTransformerInterface */ public function reverseTransform($id) { - if (!$id) { + if (null === $id) { return null; } diff --git a/src/Bundle/ChillPersonBundle/Form/DataTransformer/PersonToIdTransformer.php b/src/Bundle/ChillPersonBundle/Form/DataTransformer/PersonToIdTransformer.php index 5e7ed4043..c5c33b838 100644 --- a/src/Bundle/ChillPersonBundle/Form/DataTransformer/PersonToIdTransformer.php +++ b/src/Bundle/ChillPersonBundle/Form/DataTransformer/PersonToIdTransformer.php @@ -15,17 +15,17 @@ use Chill\PersonBundle\Entity\Person; use Doctrine\Persistence\ObjectManager; use Symfony\Component\Form\DataTransformerInterface; use Symfony\Component\Form\Exception\TransformationFailedException; +use Chill\PersonBundle\Entity\Person; +use Chill\PersonBundle\Repository\PersonRepository; +use Doctrine\ORM\EntityRepository; -class PersonToIdTransformer implements DataTransformerInterface +final class PersonToIdTransformer implements DataTransformerInterface { - /** - * @var ObjectManager - */ - private $om; + private EntityRepository $personRepository; - public function __construct(ObjectManager $om) + public function __construct(PersonRepository $personRepository) { - $this->om = $om; + $this->personRepository = $personRepository; } /** @@ -43,9 +43,8 @@ class PersonToIdTransformer implements DataTransformerInterface return null; } - $issue = $this->om - ->getRepository('ChillPersonBundle:Person') - ->findOneBy(['id' => $id]); + $issue = $this->personRepository + ->findOneBy(array('id' => $id)); if (null === $issue) { throw new TransformationFailedException(sprintf( diff --git a/src/Bundle/ChillPersonBundle/Form/Type/Select2MaritalStatusType.php b/src/Bundle/ChillPersonBundle/Form/Type/Select2MaritalStatusType.php index 742efbc7d..dd06a08f5 100644 --- a/src/Bundle/ChillPersonBundle/Form/Type/Select2MaritalStatusType.php +++ b/src/Bundle/ChillPersonBundle/Form/Type/Select2MaritalStatusType.php @@ -40,13 +40,14 @@ class Select2MaritalStatusType extends AbstractType public function buildForm(FormBuilderInterface $builder, array $options) { - $transformer = new ObjectToIdTransformer($this->em, 'Chill\PersonBundle\Entity\MaritalStatus'); + $transformer = new ObjectToIdTransformer($this->em, MaritalStatus::class); $builder->addModelTransformer($transformer); } public function configureOptions(OptionsResolver $resolver) { - $maritalStatuses = $this->em->getRepository('Chill\PersonBundle\Entity\MaritalStatus')->findAll(); + $locale = $this->requestStack->getCurrentRequest()->getLocale(); + $maritalStatuses = $this->em->getRepository(MaritalStatus::class)->findAll(); $choices = []; foreach ($maritalStatuses as $ms) {