Skip to content

Commit 12e2168

Browse files
committed
Fix stan
1 parent 1c62804 commit 12e2168

File tree

1 file changed

+11
-18
lines changed

1 file changed

+11
-18
lines changed

src/Database/Adapter/Mongo.php

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,7 @@ public function commitTransaction(): bool
177177
// This is not necessarily a failure, just return success since the transaction was already terminated.
178178
$e = $this->processException($e);
179179
if ($e instanceof TransactionException) {
180-
if ($this->session) {
181-
$this->client->endSessions([$this->session]);
182-
}
180+
$this->client->endSessions([$this->session]);
183181
$this->session = null;
184182
$this->inTransaction = 0; // Reset counter when transaction is already terminated
185183
return true;
@@ -199,12 +197,10 @@ public function commitTransaction(): bool
199197
return true;
200198
} catch (\Throwable $e) {
201199
// Ensure cleanup on any failure
202-
if ($this->session) {
203-
try {
204-
$this->client->endSessions([$this->session]);
205-
} catch (\Throwable $endSessionError) {
206-
// Ignore errors when ending session during error cleanup
207-
}
200+
try {
201+
$this->client->endSessions([$this->session]);
202+
} catch (\Throwable $endSessionError) {
203+
// Ignore errors when ending session during error cleanup
208204
}
209205
$this->session = null;
210206
$this->inTransaction = 0;
@@ -234,25 +230,22 @@ public function rollbackTransaction(): bool
234230
} catch (\Throwable $e) {
235231
throw new DatabaseException($e->getMessage(), $e->getCode(), $e);
236232
} finally {
237-
if ($this->session) {
238-
$this->client->endSessions([$this->session]);
239-
}
233+
$this->client->endSessions([$this->session]);
240234
$this->session = null;
241235
}
242236

243237
return true;
244238
}
245239
return true;
246240
} catch (\Throwable $e) {
247-
if ($this->session) {
248-
try {
249-
$this->client->endSessions([$this->session]);
250-
} catch (\Throwable $endSessionError) {
251-
// Ignore errors when ending session during error cleanup
252-
}
241+
try {
242+
$this->client->endSessions([$this->session]);
243+
} catch (\Throwable) {
244+
// Ignore errors when ending session during error cleanup
253245
}
254246
$this->session = null;
255247
$this->inTransaction = 0;
248+
256249
throw new DatabaseException('Failed to rollback transaction: ' . $e->getMessage(), $e->getCode(), $e);
257250
}
258251
}

0 commit comments

Comments
 (0)