Skip to content

Commit 768306f

Browse files
cursoragentabnegate
andcommitted
Refactor skipFilters method to improve null filter handling and exception safety
Co-authored-by: jakeb994 <jakeb994@gmail.com>
1 parent d792eb0 commit 768306f

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

src/Database/Database.php

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -819,21 +819,28 @@ public function disableFilters(): static
819819
*/
820820
public function skipFilters(callable $callback, ?array $filterNames = null): mixed
821821
{
822+
if (\is_null($filterNames)) {
823+
$initial = $this->filter;
824+
$this->disableFilters();
825+
826+
try {
827+
return $callback();
828+
} finally {
829+
$this->filter = $initial;
830+
}
831+
}
832+
822833
$previousFilter = $this->filter;
823834
$previousDisabledFilters = $this->disabledFilters;
824835

825-
if (\is_null($filterNames)) {
826-
$this->disableFilters();
836+
if (\count($filterNames) === 0) {
837+
$this->disabledFilters = [];
827838
} else {
828-
if (\count($filterNames) === 0) {
829-
$this->disabledFilters = [];
830-
} else {
831-
$disabledFilters = [];
832-
foreach ($filterNames as $filterName) {
833-
$disabledFilters[$filterName] = true;
834-
}
835-
$this->disabledFilters = $disabledFilters;
839+
$disabledFilters = [];
840+
foreach ($filterNames as $filterName) {
841+
$disabledFilters[$filterName] = true;
836842
}
843+
$this->disabledFilters = $disabledFilters;
837844
}
838845

839846
try {

0 commit comments

Comments
 (0)