Code Coverage |
||||||||||||||||
Lines |
Branches |
Paths |
Functions and Methods |
Classes and Traits |
||||||||||||
| Total | |
100.00% |
9 / 9 |
|
100.00% |
4 / 4 |
|
100.00% |
3 / 3 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| DoctrineTransactionProvider | |
100.00% |
9 / 9 |
|
100.00% |
4 / 4 |
|
100.00% |
3 / 3 |
|
100.00% |
2 / 2 |
3 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| transactional | |
100.00% |
8 / 8 |
|
100.00% |
3 / 3 |
|
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Shared\Infrastructure\Service; |
| 4 | |
| 5 | use Doctrine\ORM\EntityManagerInterface; |
| 6 | use Override; |
| 7 | use Throwable; |
| 8 | |
| 9 | final readonly class DoctrineTransactionProvider implements \App\Shared\Domain\Port\Driven\TransactionProvider |
| 10 | { |
| 11 | |
| 12 | public function __construct(private EntityManagerInterface $entityManager) |
| 13 | { |
| 14 | } |
| 15 | |
| 16 | /** |
| 17 | * @inheritDoc |
| 18 | */ |
| 19 | #[Override] |
| 20 | public function transactional(callable $callback): mixed |
| 21 | { |
| 22 | $this->entityManager->beginTransaction(); |
| 23 | |
| 24 | try { |
| 25 | $result = $callback(); |
| 26 | $this->entityManager->flush(); |
| 27 | $this->entityManager->commit(); |
| 28 | return $result; |
| 29 | } catch (Throwable $e) { |
| 30 | $this->entityManager->rollback(); |
| 31 | // TODO log the transaction error |
| 32 | // then rethrow the exception as is, because it may (should ?) be a domain Exception with meaning |
| 33 | // throw new TransactionProviderException($e); |
| 34 | throw $e; |
| 35 | } |
| 36 | } |
| 37 | } |
Below are the source code lines that represent each code path as identified by Xdebug. Please note a path is not
necessarily coterminous with a line, a line may contain multiple paths and therefore show up more than once.
Please also be aware that some paths may include implicit rather than explicit branches, e.g. an if statement
always has an else as part of its logical flow even if you didn't write one.
| 12 | public function __construct(private EntityManagerInterface $entityManager) |
| 13 | { |
| 14 | } |
| 20 | public function transactional(callable $callback): mixed |
| 21 | { |
| 22 | $this->entityManager->beginTransaction(); |
| 23 | |
| 24 | try { |
| 25 | $result = $callback(); |
| 26 | $this->entityManager->flush(); |
| 27 | $this->entityManager->commit(); |
| 28 | return $result; |
| 29 | } catch (Throwable $e) { |
| 30 | $this->entityManager->rollback(); |
| 31 | // TODO log the transaction error |
| 32 | // then rethrow the exception as is, because it may (should ?) be a domain Exception with meaning |
| 33 | // throw new TransactionProviderException($e); |
| 34 | throw $e; |
| 35 | } |
| 36 | } |
| 3 | namespace App\Shared\Infrastructure\Service; |
| 4 | |
| 5 | use Doctrine\ORM\EntityManagerInterface; |
| 6 | use Override; |
| 7 | use Throwable; |
| 8 | |
| 9 | final readonly class DoctrineTransactionProvider implements \App\Shared\Domain\Port\Driven\TransactionProvider |
| 10 | { |
| 11 | |
| 12 | public function __construct(private EntityManagerInterface $entityManager) |
| 13 | { |
| 14 | } |
| 15 | |
| 16 | /** |
| 17 | * @inheritDoc |
| 18 | */ |
| 19 | #[Override] |
| 20 | public function transactional(callable $callback): mixed |
| 21 | { |
| 22 | $this->entityManager->beginTransaction(); |
| 23 | |
| 24 | try { |
| 25 | $result = $callback(); |
| 26 | $this->entityManager->flush(); |
| 27 | $this->entityManager->commit(); |
| 28 | return $result; |
| 29 | } catch (Throwable $e) { |
| 30 | $this->entityManager->rollback(); |
| 31 | // TODO log the transaction error |
| 32 | // then rethrow the exception as is, because it may (should ?) be a domain Exception with meaning |
| 33 | // throw new TransactionProviderException($e); |
| 34 | throw $e; |
| 35 | } |
| 36 | } |