| Conditions | 4 |
| Paths | 5 |
| Total Lines | 27 |
| Code Lines | 18 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 12 |
| CRAP Score | 4.128 |
| Changes | 0 | ||
| 1 | <?php |
||
| 38 | 7 | public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface |
|
| 39 | { |
||
| 40 | 7 | $id = $request->getAttribute('id'); |
|
| 41 | 7 | $msg = new DangerMessage('Could not load Configuration by provided ID.'); |
|
| 42 | |||
| 43 | 7 | if ($id !== null) { |
|
| 44 | try { |
||
| 45 | 7 | $dbConfig = $this->entityManager->find(DbConfiguration::class, $id); |
|
| 46 | 7 | if ($dbConfig) { |
|
| 47 | 4 | return $handler->handle( |
|
| 48 | 4 | $request->withAttribute(self::DATA_RESOURCE, $dbConfig) |
|
| 49 | ); |
||
| 50 | } |
||
| 51 | } catch (ORMInvalidArgumentException | ORMException $exception) { |
||
| 52 | $this->logger->error((string)$exception); |
||
| 53 | $msg = new DangerMessage('Error during loading DB Configuration.'); |
||
| 54 | } |
||
| 55 | } |
||
| 56 | |||
| 57 | 3 | return new JsonResponse([ |
|
| 58 | 3 | 'data' => [ |
|
| 59 | 'configuration' => null, |
||
| 60 | ], |
||
| 61 | 'success' => false, |
||
| 62 | 3 | 'msg' => $msg, |
|
| 63 | 3 | ], 404); |
|
| 64 | } |
||
| 65 | } |
||
| 66 |
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.