| Conditions | 2 |
| Paths | 2 |
| Total Lines | 16 |
| Code Lines | 10 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 38 | public function prepareCategoryTableWithTwoItems() |
||
| 39 | { |
||
| 40 | if ( ! $this->isDbSchemaPrepared) { |
||
| 41 | /** @var Connection $connection */ |
||
| 42 | $this->connection->query('CREATE TABLE category (id INTEGER NOT NULL, parent_id int NULL,' |
||
| 43 | . 'path string, name string, PRIMARY KEY(id))'); |
||
| 44 | |||
| 45 | $fruitCategory = new Category('Fruit'); |
||
| 46 | $appleCategory = new Category('Apple', $fruitCategory); |
||
| 47 | |||
| 48 | $this->entityManager->persist($fruitCategory); |
||
| 49 | $this->entityManager->persist($appleCategory); |
||
| 50 | $this->entityManager->flush(); |
||
| 51 | $this->isDbSchemaPrepared = TRUE; |
||
| 52 | } |
||
| 53 | } |
||
| 54 | |||
| 56 |
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.