Code Duplication    Length = 20-21 lines in 2 locations

src/DBAL/TransactionMiddleware.php 1 location

@@ 37-56 (lines=20) @@
34
     * @throws Exception
35
     * @throws Throwable
36
     */
37
    public function execute($command, callable $next)
38
    {
39
        $this->connection->beginTransaction();
40
41
        try {
42
            $returnValue = $next($command);
43
44
            $this->connection->commit();
45
        } catch (Exception $exception) {
46
            $this->connection->rollBack();
47
48
            throw $exception;
49
        } catch (Throwable $exception) {
50
            $this->connection->rollBack();
51
52
            throw $exception;
53
        }
54
55
        return $returnValue;
56
    }
57
}
58

src/ORM/TransactionMiddleware.php 1 location

@@ 36-56 (lines=21) @@
33
     * @throws Throwable
34
     * @throws Exception
35
     */
36
    public function execute($command, callable $next)
37
    {
38
        $this->entityManager->beginTransaction();
39
40
        try {
41
            $returnValue = $next($command);
42
43
            $this->entityManager->flush();
44
            $this->entityManager->commit();
45
        } catch (Exception $e) {
46
            $this->rollbackTransaction();
47
48
            throw $e;
49
        } catch (Throwable $e) {
50
            $this->rollbackTransaction();
51
52
            throw $e;
53
        }
54
55
        return $returnValue;
56
    }
57
58
    /**
59
     * Rollback the current transaction and close the entity manager when possible.