| Conditions | 3 |
| Paths | 7 |
| Total Lines | 16 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 8 |
| CRAP Score | 3.1825 |
| Changes | 0 | ||
| 1 | <?php |
||
| 18 | 12 | public function saveAllInTransaction(EntityInterface ...$entities): void |
|
| 19 | { |
||
| 20 | /** @var EntityManagerInterface $entityManager */ |
||
| 21 | 12 | $entityManager = $this->getEntityManager(); |
|
|
|
|||
| 22 | 12 | $entityManager->getConnection()->beginTransaction(); |
|
| 23 | try { |
||
| 24 | 12 | foreach ($entities as $entity) { |
|
| 25 | 12 | $entityManager->persist($entity); |
|
| 26 | } |
||
| 27 | 12 | $entityManager->flush(); |
|
| 28 | 12 | $entityManager->getConnection()->commit(); |
|
| 29 | } catch (\Throwable $e) { |
||
| 30 | $entityManager->getConnection()->rollBack(); |
||
| 31 | throw $e; |
||
| 32 | } |
||
| 33 | 12 | } |
|
| 34 | |||
| 55 |
This check looks for methods that are used by a trait but not required by it.
To illustrate, let’s look at the following code example
The trait
Idableprovides a methodequalsIdthat in turn relies on the methodgetId(). If this method does not exist on a class mixing in this trait, the method will fail.Adding the
getId()as an abstract method to the trait will make sure it is available.