| Conditions | 4 |
| Paths | 3 |
| Total Lines | 23 |
| Code Lines | 13 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 34 | public function reverseTransform($value) |
||
| 35 | { |
||
| 36 | if (null === $value || '' === $value) { |
||
| 37 | return null; |
||
| 38 | } |
||
| 39 | |||
| 40 | if (!is_string($value)) { |
||
| 41 | throw new UnexpectedTypeException($value, 'string'); |
||
| 42 | } |
||
| 43 | |||
| 44 | $dql = <<<DQL |
||
| 45 | SELECT i |
||
| 46 | FROM AppBundle:Invitation i |
||
| 47 | WHERE i.code = :code |
||
| 48 | AND NOT EXISTS(SELECT 1 FROM AppBundle:User u WHERE u.invitation = i) |
||
| 49 | DQL; |
||
| 50 | |||
| 51 | return $this->entityManager |
||
| 52 | ->createQuery($dql) |
||
| 53 | ->setParameter('code', $value) |
||
| 54 | ->setMaxResults(1) |
||
| 55 | ->getOneOrNullResult(); |
||
| 56 | } |
||
| 57 | } |
||
| 58 |
The
EntityManagermight become unusable for example if a transaction is rolled back and it gets closed. Let’s assume that somewhere in your application, or in a third-party library, there is code such as the following:If that code throws an exception and the
EntityManageris closed. Any other code which depends on the same instance of theEntityManagerduring this request will fail.On the other hand, if you instead inject the
ManagerRegistry, thegetManager()method guarantees that you will always get a usable manager instance.