Code Coverage
 
Lines
Branches
Paths
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
DoctrineTransactionProvider
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
2 / 2
3
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 transactional
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2
3namespace App\Shared\Infrastructure\Service;
4
5use Doctrine\ORM\EntityManagerInterface;
6use Override;
7use Throwable;
8
9final 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}

Branches

Below are the source code lines that represent each code branch as identified by Xdebug. Please note a branch is not necessarily coterminous with a line, a line may contain multiple branches and therefore show up more than once. Please also be aware that some branches may be implicit rather than explicit, e.g. an if statement always has an else as part of its logical flow even if you didn't write one.

DoctrineTransactionProvider->__construct
12    public function __construct(private EntityManagerInterface $entityManager)
13    {
14    }
DoctrineTransactionProvider->transactional
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    }
{main}
3namespace App\Shared\Infrastructure\Service;
4
5use Doctrine\ORM\EntityManagerInterface;
6use Override;
7use Throwable;
8
9final 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    }